Building Selection started + Outline
This commit is contained in:
File diff suppressed because it is too large
Load Diff
21
Assets/Game/Scripts/Building.cs
Normal file
21
Assets/Game/Scripts/Building.cs
Normal file
@@ -0,0 +1,21 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class Building : MonoBehaviour
|
||||
{
|
||||
public string buildingName = "building01";
|
||||
public Outline outline;
|
||||
|
||||
void Awake(){
|
||||
if(outline == null){outline = GetComponent<Outline>();}
|
||||
outline.enabled=false;
|
||||
Selector.OnSelectedChanged.AddListener(OnSelectedChanged);
|
||||
}
|
||||
|
||||
void OnSelectedChanged(){
|
||||
if(Selector.selectedBuilding == null){outline.enabled=false; return;}
|
||||
|
||||
outline.enabled = Selector.selectedBuilding == this;
|
||||
}
|
||||
}
|
||||
11
Assets/Game/Scripts/Building.cs.meta
Normal file
11
Assets/Game/Scripts/Building.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b71079c276d1984cd82ae7c982fe5ca7
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
49
Assets/Game/Scripts/CameraController.cs
Normal file
49
Assets/Game/Scripts/CameraController.cs
Normal file
@@ -0,0 +1,49 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
|
||||
public class CameraController : MonoBehaviour
|
||||
{
|
||||
public Transform cam;
|
||||
public float sensitivity;
|
||||
|
||||
void Start()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void Update()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
private Vector2 mouseStartPos = Vector2.zero;
|
||||
private Vector3 cameraStartPos = Vector2.zero;
|
||||
public bool moving = false;
|
||||
public void OnMouseDown(BaseEventData e){
|
||||
#if UNITY_EDITOR
|
||||
PointerEventData ped = (PointerEventData) e as PointerEventData;
|
||||
mouseStartPos = ped.position;
|
||||
cameraStartPos = cam.transform.position;
|
||||
moving=true;
|
||||
#endif
|
||||
}
|
||||
public void OnMouseUp(BaseEventData e){
|
||||
#if UNITY_EDITOR
|
||||
PointerEventData ped = (PointerEventData) e as PointerEventData;
|
||||
moving=false;
|
||||
#endif
|
||||
}
|
||||
public void OnMouseMove(BaseEventData e){
|
||||
#if UNITY_EDITOR
|
||||
PointerEventData ped = (PointerEventData) e as PointerEventData;
|
||||
if(moving){
|
||||
Vector3 offset = (mouseStartPos-ped.position) * sensitivity;
|
||||
cam.transform.position = cameraStartPos + new Vector3(offset.x,0,offset.y);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
11
Assets/Game/Scripts/CameraController.cs.meta
Normal file
11
Assets/Game/Scripts/CameraController.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: cf95a4372862ef3d7b3076cf3530ac7c
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
63
Assets/Game/Scripts/New Lighting Settings.lighting
Normal file
63
Assets/Game/Scripts/New Lighting Settings.lighting
Normal file
@@ -0,0 +1,63 @@
|
||||
%YAML 1.1
|
||||
%TAG !u! tag:unity3d.com,2011:
|
||||
--- !u!850595691 &4890085278179872738
|
||||
LightingSettings:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_Name: New Lighting Settings
|
||||
serializedVersion: 3
|
||||
m_GIWorkflowMode: 1
|
||||
m_EnableBakedLightmaps: 1
|
||||
m_EnableRealtimeLightmaps: 0
|
||||
m_RealtimeEnvironmentLighting: 1
|
||||
m_BounceScale: 1
|
||||
m_AlbedoBoost: 1
|
||||
m_IndirectOutputScale: 1
|
||||
m_UsingShadowmask: 1
|
||||
m_BakeBackend: 1
|
||||
m_LightmapMaxSize: 1024
|
||||
m_BakeResolution: 40
|
||||
m_Padding: 2
|
||||
m_TextureCompression: 1
|
||||
m_AO: 0
|
||||
m_AOMaxDistance: 1
|
||||
m_CompAOExponent: 1
|
||||
m_CompAOExponentDirect: 0
|
||||
m_ExtractAO: 0
|
||||
m_MixedBakeMode: 2
|
||||
m_LightmapsBakeMode: 1
|
||||
m_FilterMode: 1
|
||||
m_LightmapParameters: {fileID: 15204, guid: 0000000000000000f000000000000000, type: 0}
|
||||
m_ExportTrainingData: 0
|
||||
m_TrainingDataDestination: TrainingData
|
||||
m_RealtimeResolution: 2
|
||||
m_ForceWhiteAlbedo: 0
|
||||
m_ForceUpdates: 0
|
||||
m_FinalGather: 0
|
||||
m_FinalGatherRayCount: 256
|
||||
m_FinalGatherFiltering: 1
|
||||
m_PVRCulling: 1
|
||||
m_PVRSampling: 1
|
||||
m_PVRDirectSampleCount: 32
|
||||
m_PVRSampleCount: 512
|
||||
m_PVREnvironmentSampleCount: 256
|
||||
m_PVREnvironmentReferencePointCount: 2048
|
||||
m_LightProbeSampleCountMultiplier: 4
|
||||
m_PVRBounces: 2
|
||||
m_PVRMinBounces: 1
|
||||
m_PVREnvironmentMIS: 1
|
||||
m_PVRFilteringMode: 1
|
||||
m_PVRDenoiserTypeDirect: 1
|
||||
m_PVRDenoiserTypeIndirect: 1
|
||||
m_PVRDenoiserTypeAO: 1
|
||||
m_PVRFilterTypeDirect: 0
|
||||
m_PVRFilterTypeIndirect: 0
|
||||
m_PVRFilterTypeAO: 0
|
||||
m_PVRFilteringGaussRadiusDirect: 1
|
||||
m_PVRFilteringGaussRadiusIndirect: 5
|
||||
m_PVRFilteringGaussRadiusAO: 2
|
||||
m_PVRFilteringAtrousPositionSigmaDirect: 0.5
|
||||
m_PVRFilteringAtrousPositionSigmaIndirect: 2
|
||||
m_PVRFilteringAtrousPositionSigmaAO: 1
|
||||
8
Assets/Game/Scripts/New Lighting Settings.lighting.meta
Normal file
8
Assets/Game/Scripts/New Lighting Settings.lighting.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: cc8215393c0aa2376b270ea118bcf66f
|
||||
NativeFormatImporter:
|
||||
externalObjects: {}
|
||||
mainObjectFileID: 4890085278179872738
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
65
Assets/Game/Scripts/WorldItemSelector.cs
Normal file
65
Assets/Game/Scripts/WorldItemSelector.cs
Normal file
@@ -0,0 +1,65 @@
|
||||
using UnityEngine.UI;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
using UnityEngine.Events;
|
||||
|
||||
public class WorldItemSelector : MonoBehaviour
|
||||
{
|
||||
public float moveThreshold = 1;
|
||||
public LayerMask layerMask;
|
||||
|
||||
public Transform selectedItemUI;
|
||||
public void SelectScreenPoint(Vector2 screenPoint){
|
||||
Ray ray = Camera.main.ScreenPointToRay(screenPoint);
|
||||
RaycastHit hit = new RaycastHit();
|
||||
|
||||
if(Physics.Raycast(ray,out hit, Mathf.Infinity, layerMask)){
|
||||
Building selectedB = hit.collider.GetComponent<Building>();
|
||||
if(selectedB!=null){
|
||||
Debug.Log("Selected building : " + selectedB.buildingName);
|
||||
Selector.selectBuilding(selectedB);
|
||||
}else{
|
||||
Debug.Log("No target here, Unselecting");
|
||||
Selector.selectBuilding(null);
|
||||
}
|
||||
RefreshUI();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void RefreshUI(){
|
||||
selectedItemUI.gameObject.SetActive(Selector.selectedBuilding !=null);
|
||||
if(Selector.selectedBuilding!=null){
|
||||
selectedItemUI.GetChild(0).GetComponent<Text>().text = Selector.selectedBuilding.buildingName;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private Vector2 startedPos= Vector2.zero;
|
||||
public void OnPointerDown(BaseEventData e){
|
||||
PointerEventData ped = (PointerEventData) e as PointerEventData;
|
||||
startedPos = ped.position;
|
||||
}
|
||||
|
||||
public void OnPointerUp(BaseEventData e){
|
||||
PointerEventData ped = (PointerEventData) e as PointerEventData;
|
||||
float pointerDiff = Mathf.Abs(ped.position.magnitude - startedPos.magnitude);
|
||||
if(pointerDiff < moveThreshold){
|
||||
SelectScreenPoint(ped.position);
|
||||
}else{
|
||||
Debug.Log("Pointer moved (" + pointerDiff+ "), Not gonna select item");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static class Selector{
|
||||
public static Building selectedBuilding;
|
||||
public static UnityEvent OnSelectedChanged = new UnityEvent();
|
||||
|
||||
public static void selectBuilding(Building e){
|
||||
selectedBuilding = e;
|
||||
OnSelectedChanged.Invoke();
|
||||
}
|
||||
}
|
||||
11
Assets/Game/Scripts/WorldItemSelector.cs.meta
Normal file
11
Assets/Game/Scripts/WorldItemSelector.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f8e2a2577a946b0039812137d2f8245f
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user