|
|
@ -1,6 +1,7 @@ |
|
|
|
using System.Collections; |
|
|
|
using System.Collections.Generic; |
|
|
|
using UnityEngine; |
|
|
|
using UnityEngine.UI; |
|
|
|
|
|
|
|
public class ParentBehaviour : MonoBehaviour |
|
|
|
{ |
|
|
@ -31,8 +32,11 @@ public class ParentBehaviour : MonoBehaviour |
|
|
|
|
|
|
|
private void Start() |
|
|
|
{ |
|
|
|
parentBodyObj.GetComponent<MeshRenderer>().material.mainTexture = parentBases[Random.Range(0, parentBases.Length)]; |
|
|
|
parentFaceObj.GetComponent<MeshRenderer>().material.mainTexture = parentFaceNeutral; |
|
|
|
Texture _displayGraphic = parentBases[Random.Range(0, parentBases.Length)]; |
|
|
|
parentBodyObj.GetComponent<Image>().sprite = Sprite.Create((Texture2D)_displayGraphic, new Rect(0.0f, 0.0f, _displayGraphic.width, _displayGraphic.height), new Vector2(0.5f, 0.5f), 100.0f); |
|
|
|
|
|
|
|
_displayGraphic = parentFaceNeutral; |
|
|
|
parentFaceObj.GetComponent<Image>().sprite = Sprite.Create((Texture2D)_displayGraphic, new Rect(0.0f, 0.0f, _displayGraphic.width, _displayGraphic.height), new Vector2(0.5f, 0.5f), 100.0f); |
|
|
|
} |
|
|
|
|
|
|
|
[ContextMenu("Get Random Child")] |
|
|
@ -45,13 +49,10 @@ public class ParentBehaviour : MonoBehaviour |
|
|
|
|
|
|
|
child = babySpawner.transform.GetChild(_childIndex).gameObject; |
|
|
|
|
|
|
|
if (otherParent.child != null) |
|
|
|
if (!ReferenceEquals(child, otherParent.child) || otherParent.child == null) |
|
|
|
{ |
|
|
|
if (child != otherParent.child) |
|
|
|
{ |
|
|
|
//this prevents both parents asking for the same child
|
|
|
|
_validChild = true; |
|
|
|
} |
|
|
|
//this prevents both parents asking for the same child
|
|
|
|
_validChild = true; |
|
|
|
} |
|
|
|
} |
|
|
|
Randomizer _childRandomizer = child.GetComponent<Randomizer>(); |
|
|
@ -67,6 +68,8 @@ public class ParentBehaviour : MonoBehaviour |
|
|
|
order.Insert(Random.Range(0, order.Count), "eye"); |
|
|
|
order.Insert(Random.Range(0, order.Count), "top"); |
|
|
|
order.Insert(Random.Range(0, order.Count), "bottom"); |
|
|
|
|
|
|
|
GiveFirstDetail(); |
|
|
|
} |
|
|
|
|
|
|
|
public bool CheckChild(GameObject _child) |
|
|
@ -83,36 +86,43 @@ public class ParentBehaviour : MonoBehaviour |
|
|
|
|
|
|
|
public Texture GiveDetails(GameObject _child) |
|
|
|
{ |
|
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < order.Count; i++) |
|
|
|
{ |
|
|
|
switch (order[i]){ |
|
|
|
case "base": |
|
|
|
if (child.GetComponent<Randomizer>().baseObj.GetComponent<MeshRenderer>().material.mainTexture != baseVis) |
|
|
|
if (_child.GetComponent<Randomizer>().baseObj.GetComponent<MeshRenderer>().material.mainTexture.name != baseVis.name) |
|
|
|
{ |
|
|
|
print("returning baseVis"); |
|
|
|
return baseVis; |
|
|
|
} |
|
|
|
break; |
|
|
|
case "hat": |
|
|
|
if (child.GetComponent<Randomizer>().hatObj.GetComponent<MeshRenderer>().material.mainTexture != hatVis) |
|
|
|
if (_child.GetComponent<Randomizer>().hatObj.GetComponent<MeshRenderer>().material.mainTexture.name != hatVis.name) |
|
|
|
{ |
|
|
|
print("returning hatVis"); |
|
|
|
return hatVis; |
|
|
|
} |
|
|
|
break; |
|
|
|
case "eye": |
|
|
|
if (child.GetComponent<Randomizer>().eyeObj.GetComponent<MeshRenderer>().material.mainTexture != eyeVis) |
|
|
|
if (_child.GetComponent<Randomizer>().eyeObj.GetComponent<MeshRenderer>().material.mainTexture.name != eyeVis.name) |
|
|
|
{ |
|
|
|
print("returning eyeVis"); |
|
|
|
return eyeVis; |
|
|
|
} |
|
|
|
break; |
|
|
|
case "top": |
|
|
|
if (child.GetComponent<Randomizer>().topObj.GetComponent<MeshRenderer>().material.mainTexture != topVis) |
|
|
|
if (_child.GetComponent<Randomizer>().topObj.GetComponent<MeshRenderer>().material.mainTexture.name != topVis.name) |
|
|
|
{ |
|
|
|
print("returning topVis"); |
|
|
|
return topVis; |
|
|
|
} |
|
|
|
break; |
|
|
|
case "bottom": |
|
|
|
if (child.GetComponent<Randomizer>().bottomObj.GetComponent<MeshRenderer>().material.mainTexture != bottomVis) |
|
|
|
if (_child.GetComponent<Randomizer>().bottomObj.GetComponent<MeshRenderer>().material.mainTexture.name != bottomVis.name) |
|
|
|
{ |
|
|
|
print("returning bottomVis"); |
|
|
|
return bottomVis; |
|
|
|
} |
|
|
|
break; |
|
|
@ -123,21 +133,50 @@ public class ParentBehaviour : MonoBehaviour |
|
|
|
return null; |
|
|
|
} |
|
|
|
|
|
|
|
private void OnTriggerEnter(Collider other) |
|
|
|
public void GiveFirstDetail() |
|
|
|
{ |
|
|
|
if (other.gameObject.tag == "child") |
|
|
|
Texture _displayGraphic; |
|
|
|
switch (order[0]) |
|
|
|
{ |
|
|
|
if (CheckChild(other.gameObject)) |
|
|
|
{ |
|
|
|
//this is the correct child
|
|
|
|
} |
|
|
|
else |
|
|
|
case "base": |
|
|
|
_displayGraphic = baseVis; |
|
|
|
break; |
|
|
|
case "hat": |
|
|
|
_displayGraphic = hatVis; |
|
|
|
break; |
|
|
|
case "eye": |
|
|
|
_displayGraphic = eyeVis; |
|
|
|
break; |
|
|
|
case "top": |
|
|
|
_displayGraphic = topVis; |
|
|
|
break; |
|
|
|
case "bottom": |
|
|
|
_displayGraphic = bottomVis; |
|
|
|
break; |
|
|
|
default: |
|
|
|
_displayGraphic = null; |
|
|
|
break; |
|
|
|
} |
|
|
|
parentDialougeObj.GetComponent<Image>().sprite = Sprite.Create((Texture2D)_displayGraphic, new Rect(0.0f, 0.0f, _displayGraphic.width, _displayGraphic.height), new Vector2(0.5f, 0.5f), 100.0f); |
|
|
|
} |
|
|
|
|
|
|
|
private void OnCollisionEnter(Collision collision) |
|
|
|
{ |
|
|
|
if (child != null) |
|
|
|
{ |
|
|
|
if (collision.collider.gameObject.tag == "Child") |
|
|
|
{ |
|
|
|
Texture _displayGraphic = GiveDetails(other.gameObject); |
|
|
|
//display the display graphic
|
|
|
|
parentDialougeObj.GetComponent<MeshRenderer>().material.mainTexture = _displayGraphic; |
|
|
|
if (CheckChild(collision.collider.gameObject)) |
|
|
|
{ |
|
|
|
//this is the correct child
|
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
Texture _displayGraphic = GiveDetails(collision.collider.gameObject); |
|
|
|
//display the display graphic
|
|
|
|
parentDialougeObj.GetComponent<Image>().sprite = Sprite.Create((Texture2D)_displayGraphic, new Rect(0.0f, 0.0f, _displayGraphic.width, _displayGraphic.height), new Vector2(0.5f, 0.5f), 100.0f); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |