Ejemplo n.º 1
0
        void RelinkParent(int selfId, int newParentId)
        {
            //GetNode
            PartNode selfNode = its.GetNode(selfId);
            PartNode oldPNode = its.GetNode(selfNode.parentId);
            PartNode newPNode = its.GetNode(newParentId);

            //old parent Node remove selfId
            for (int i = oldPNode.childIds.Count - 1; i >= 0; i--)
            {
                if (oldPNode.childIds [i] == selfId)
                {
                    oldPNode.childIds.RemoveAt(i);
                    oldPNode.childHides.RemoveAt(i);
                }
            }
            //new parent Node add selfId
            if (!newPNode.childIds.Contains(selfId))
            {
                newPNode.childIds.Add(selfId);
                newPNode.childHides.Add(true);
            }
            //fix self Node
            selfNode.parentId = newParentId;
        }
Ejemplo n.º 2
0
        void GenerateTree(PartNode _partNode, PartNode _rootNode, bool _isHide = false)
        {
            //Generate _partNode
            if (_partNode.part)
            {
                Debug.Log("Generate Part : " + _partNode.part.name + "\n");
                // Art inside Part
                _partNode.part_Instance = CreatePart(_partNode.Tpos, _partNode.Trot, _partNode.part.gameObject, _rootNode.part_Instance);
                _partNode.part_Instance.SetActive(!_isHide);
                _partNode.part      = _partNode.part_Instance.GetComponent <ItemPart> ();
                _partNode.part.item = this;

                if (_partNode.part.appearance)
                {
                    _partNode.app_Instance = CreatePart(Vector3.zero, Vector3.zero, _partNode.part.appearance, _partNode.part_Instance);
                    _partNode.app_Instance.SetActive(!_isHide);
                }
            }

            //Generate _partNode.Childs
            for (int i = 0; i < _partNode.childIds.Count; i++)
            {
                PartNode cNode = GetNode(_partNode.childIds [i]);
                bool     cHide = _partNode.childHides [i];
                GenerateTree(cNode, _partNode, cHide);
            }
        }
Ejemplo n.º 3
0
 void Restore()
 {
     rootNode  = rootNode_backup.Clone();
     partNodes = new List <PartNode> ();
     foreach (PartNode pn in partNodes_backup)
     {
         partNodes.Add(pn.Clone());
     }
 }
Ejemplo n.º 4
0
 void Backup()
 {
     rootNode_backup  = rootNode.Clone();
     partNodes_backup = new List <PartNode> ();
     foreach (PartNode pn in partNodes)
     {
         partNodes_backup.Add(pn.Clone());
     }
 }
Ejemplo n.º 5
0
 void CleanChildId(PartNode pn)
 {
     for (int i = pn.childIds.Count - 1; i >= 0; i--)
     {
         if (pn.childIds [i] >= p_partNodes.arraySize)
         {
             pn.childIds.RemoveAt(i);
             pn.childHides.RemoveAt(i);
         }
     }
 }
Ejemplo n.º 6
0
        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;
        }
Ejemplo n.º 7
0
 void DrawTree(PartNode parentNode)
 {
     if (parentNode.childIds.Count > 0)
     {
         foreach (int i in parentNode.childIds)
         {
             DrawNode(i);
             if (i < its.partNodes.Count && its.partNodes [i].showChild)
             {
                 EditorGUI.indentLevel++;
                 DrawTree(its.partNodes [i]);
                 EditorGUI.indentLevel--;
             }
         }
     }
 }
Ejemplo n.º 8
0
        public PartNode Clone()
        {
            PartNode clone = new PartNode();

            clone.Tpos     = Tpos;
            clone.Trot     = Trot;
            clone.part     = part;
            clone.parentId = parentId;
            foreach (bool h in childHides)
            {
                clone.childHides.Add(h);
            }
            foreach (int i in childIds)
            {
                clone.childIds.Add(i);
            }
            return(clone);
        }
Ejemplo n.º 9
0
        void DrawNode(int index)
        {
            PartNode n = its.GetNode(index);

            if (n == null)
            {
                return;
            }
            while (its.partNodes[index].childHides.Count < its.partNodes[index].childIds.Count)
            {
                its.partNodes[index].childHides.Add(false);
            }
            if (simple)
            {
                EditorGUI.indentLevel += 2;
                EditorGUILayout.LabelField(n.part != null ? n.part.name : "None", GUILayout.Width(200));
                EditorGUI.indentLevel -= 2;
                Rect r = GUILayoutUtility.GetLastRect();
                EditorGUI.LabelField(r, index.ToString(), EditorStyles.boldLabel);
                if (n.childIds.Count > 0)
                {
                    n.showChild = EditorGUI.Foldout(r, n.showChild, "");
                }
                bool pI_Show = n.part_Instance != null && n.part_Instance.activeInHierarchy;
                r = EditorGUI.IndentedRect(r);
                Rect ri = new Rect(r.x + r.height + 2, r.y + 2, r.height - 3, r.height - 3);
                GUI.Box(ri, "", pI_Show ? "WinBtnMinMac" : "WinBtnInactiveMac");
            }
            else
            {
                EditorGUILayout.PropertyField(p_partNodes.GetArrayElementAtIndex(index));
                Rect r = GUILayoutUtility.GetLastRect();
                EditorGUI.LabelField(r, index.ToString(), EditorStyles.boldLabel);
                if (n.childIds.Count > 0)
                {
                    n.showChild = EditorGUI.Foldout(r, n.showChild, "");
                }
            }
        }