Created
September 6, 2018 08:48
-
-
Save twobob/5c474c4a0ae7ee6e616e870dc2d54449 to your computer and use it in GitHub Desktop.
basic bitch click thingy for prefabs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Collections; | |
using System.Collections.Generic; | |
using UnityEngine; | |
public class OnClickManageBuilding : MonoBehaviour { | |
public GameObject buildingPrefab; | |
public Material selectedMaterial; | |
public Material defaultMaterial; | |
public Material destroyMaterial; | |
public Material createMaterial; | |
public Material busyMaterial; | |
private GameObject clone; | |
private bool isBusy = false; | |
private bool isCreated = false; | |
private ZoomToTarget refZoomer; | |
public void SetActive() { | |
this.isBusy = false; | |
} | |
public void SetComplete() | |
{ | |
this.isBusy = false; | |
isCreated = true; | |
gameObject.GetComponent<MeshRenderer>().sharedMaterial = defaultMaterial; | |
} | |
public void Reset() | |
{ | |
GameObject.Destroy(clone); | |
isBusy = false; | |
isCreated = false; | |
gameObject.GetComponent<MeshRenderer>().sharedMaterial = defaultMaterial; | |
} | |
// Use this for initialization | |
void Start () { | |
if (buildingPrefab == null) | |
Debug.Assert(buildingPrefab == null); | |
gameObject.GetComponent<MeshRenderer>().sharedMaterial = defaultMaterial; | |
} | |
private bool checkIscomplete() { | |
if (clone != null) | |
{ | |
if (refZoomer == null) | |
{ | |
refZoomer = clone.GetComponent<ZoomToTarget>(); | |
} | |
return refZoomer.complete; | |
} | |
return false; | |
} | |
private void OnMouseOver() | |
{ | |
isCreated = checkIscomplete(); | |
if (isCreated) | |
{ | |
isBusy = false; | |
} | |
if (isBusy) | |
return; | |
if (isCreated) | |
gameObject.GetComponent<MeshRenderer>().sharedMaterial = destroyMaterial; | |
else | |
gameObject.GetComponent<MeshRenderer>().sharedMaterial = createMaterial; | |
} | |
private void OnMouseExit() | |
{ | |
if (isBusy) | |
return; | |
gameObject.GetComponent<MeshRenderer>().sharedMaterial = defaultMaterial; | |
} | |
private void OnMouseUp() | |
{ | |
if (isBusy) | |
return; | |
if (isCreated) | |
{ | |
Reset(); | |
return; | |
} | |
clone = Instantiate(buildingPrefab); | |
isBusy = true; | |
gameObject.GetComponent<MeshRenderer>().sharedMaterial = busyMaterial; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment