public PartNode() { Tpos = Vector3.zero; Trot = Vector3.zero; part = null; part_Instance = null; app_Instance = null; parentId = -1; childHides = new List <bool> (); childIds = new List <int> (); }
public void DestroyPart(ItemPart _part, bool _destroyChild = false) { //get self partnode & id int id = partNodes.FindIndex(p => p.part == _part); PartNode selfNode = GetNode(id); //get parent partnode & id int pId = id < 0 ? -1 : selfNode.parentId; PartNode parentNode = GetNode(pId); if (_destroyChild) { for (int i = selfNode.childIds.Count - 1; i > -1; i--) { int cId = selfNode.childIds [i]; PartNode childNode = GetNode(cId); Destroy(childNode.part_Instance); } } else { //relink child to parent foreach (var cId in selfNode.childIds) { PartNode childNode = GetNode(cId); if (childNode == null || !childNode.part_Instance) { Debug.LogWarning("Node[" + cId + "] is missing!!!"); continue; } if (!parentNode.childIds.Contains(cId)) { parentNode.childIds.Add(cId); parentNode.childHides.Add(false); } childNode.parentId = pId; childNode.part_Instance.transform.parent = parentNode.part_Instance.transform; childNode.app_Instance.SetActive(true); childNode.part_Instance.SetActive(true); } } // clear self int index = parentNode.childIds.FindIndex(val => val == id); if (index > -1) { parentNode.childIds.RemoveAt(index); parentNode.childHides.RemoveAt(index); } Destroy(selfNode.part_Instance); selfNode.part_Instance = null; selfNode.app_Instance = null; }
void OnTriggerEnter(Collider c) { ItemPart _hitPart = c.gameObject.GetComponent <ItemPart> (); if (_hitPart != null) { CheckHit(_hitPart); CheckPartLife(); // if (item != null) // item.UpdateParts (); } }
void CheckHit(ItemPart _hitPart) { if (!isSolid) { return; } bool destroyFlag = false; foreach (var atomA in atoms) { foreach (Atom atomB in _hitPart.atoms) { destroyFlag |= atomA.Hit(atomB) == AtomResult.destroy; } } if (destroyFlag) { Debug.Log("<" + GetInstanceID() + "><color=red>" + name + "</color> was destroyed by " + "<" + _hitPart.GetInstanceID() + "><color=orange>" + _hitPart.name + "</color>\n"); DestroySelf(); } }