예제 #1
0
    public void Refesh(int _refeshIndex)
    {
        if (_refeshIndex == mRefeshIndex)
        {
            return;
        }
        mRefeshIndex = _refeshIndex;

        mGroupID = 0;
        for (int i = 0; i < mListNode.Count; i++)
        {
            if (mListNode[i] == null)
            {
                mListNode.RemoveAt(i);
                i--;
            }
            else
            {
                mListNode[i].Refesh(_refeshIndex);
            }
        }
        for (int i = 0; i < transform.childCount; i++)
        {
            Transform      child     = transform.GetChild(i);
            PathNodeEditor nodechild = child.GetComponent <PathNodeEditor>();
            if (nodechild != null)
            {
                nodechild.Refesh(_refeshIndex);
            }
        }
    }
 public void Refesh()
 {
     mRefeshIndex++;
     for (int i = 0; i < transform.childCount; i++)
     {
         Transform      trans      = transform.GetChild(i);
         PathNodeEditor nodeeditor = trans.GetComponent <PathNodeEditor>();
         if (nodeeditor != null)
         {
             nodeeditor.Refesh(mRefeshIndex);
         }
     }
 }
예제 #3
0
    public void DrawGizmos()
    {
        for (int i = 0; i < mListNodes.Count; i++)
        {
            PathNode node = mListNodes[i];
            Gizmos.color = Color.yellow;
            Gizmos.DrawWireSphere(node.mPosition, PathNodeEditor.GetHandleSize(node.mPosition));

            for (int j = 0; j < node.mLink.Count; j++)
            {
                PathNode link_node = node.mLink[j];
                Gizmos.color = Color.blue;
                Gizmos.DrawLine(node.mPosition, link_node.mPosition);
            }
        }
    }
예제 #4
0
    public override void OnInspectorGUI()
    {
        serializedObject.Update();
        PathNodeCreateEditor nodecreater = target as PathNodeCreateEditor;

        for (int i = 0; i < nodecreater.transform.childCount; i++)
        {
            Transform trans = nodecreater.transform.GetChild(i);
            EditorGUILayout.ObjectField("Group " + i, trans, typeof(Transform), true);
        }

        GUILayout.BeginHorizontal();
        if (GUILayout.Button("Create new Group"))
        {
            GameObject obj = GameObject.CreatePrimitive(PrimitiveType.Cube);
            obj.name = "node";
            PathNodeEditor node = obj.AddComponent <PathNodeEditor>();
            obj.transform.parent        = nodecreater.transform;
            obj.transform.localPosition = nodecreater.transform.localPosition;
        }
        if (GUILayout.Button("Refesh"))
        {
            nodecreater.Refesh();
        }
        if (GUILayout.Button("Save"))
        {
            string pathfile = EditorUtility.SaveFilePanel("Save Asset...", Application.dataPath, "", "bytes");
            if (pathfile != string.Empty)
            {
                nodecreater.SaveBinary(pathfile);
            }
        }
        if (GUILayout.Button("Load"))
        {
            string pathfile = EditorUtility.OpenFilePanel("Load Asset...", Application.dataPath, "bytes");
            if (pathfile != string.Empty)
            {
                nodecreater.LoadBinary(pathfile);
            }
        }
        GUILayout.EndHorizontal();
        serializedObject.ApplyModifiedProperties();
    }
예제 #5
0
    public override void OnInspectorGUI()
    {
        serializedObject.Update();
        PathNodeEditor pathnode = target as PathNodeEditor;

        // EditorGUILayout.PropertyField(mAddObj);
        mAddObj = EditorGUILayout.ObjectField("Link", mAddObj, typeof(PathNodeEditor), true, GUILayout.Height(100)) as PathNodeEditor;
        if (mAddObj != null)
        {
            if (mAddObj != pathnode)
            {
                if (pathnode.mListNode.IndexOf(mAddObj) < 0)
                {
                    pathnode.mListNode.Add(mAddObj);
                    if (mAddObj.mListNode.IndexOf(pathnode) < 0)
                    {
                        mAddObj.mListNode.Add(pathnode);
                    }
                }
                else
                {
                    pathnode.mListNode.Remove(mAddObj);
                    mAddObj.mListNode.Remove(pathnode);
                }
            }
            mAddObj = null;
        }
        pathnode.mName = EditorGUILayout.TextField("Name", pathnode.mName);
        EditorGUILayout.IntField("GroupID", pathnode.mGroupID);
        pathnode.mValue = EditorGUILayout.IntField("Value", pathnode.mValue);
        EditorGUILayout.PropertyField(serializedObject.FindProperty("mListNode"), true);
        if (GUILayout.Button("Create new one"))
        {
            GameObject obj = GameObject.CreatePrimitive(PrimitiveType.Cube);
            obj.name = "node";
            PathNodeEditor node = obj.AddComponent <PathNodeEditor>();
            obj.transform.parent        = pathnode.transform.parent;
            obj.transform.localPosition = pathnode.transform.localPosition;
            Selection.activeGameObject  = obj;
        }
        serializedObject.ApplyModifiedProperties();
    }
예제 #6
0
    void OnSceneGUI()
    {
        PathNodeEditor pathnode = target as PathNodeEditor;
        Vector3        wpPos    = pathnode.transform.position;
        float          size     = HandleUtility.GetHandleSize(wpPos) * 0.4f;

        //do not draw waypoint header if too far away
        if (size < 3f)
        {
            //begin 2D GUI block
            Handles.BeginGUI();
            //translate waypoint vector3 position in world space into a position on the screen
            var guiPoint = HandleUtility.WorldToGUIPoint(wpPos);
            //create rectangle with that positions and do some offset
            var rect = new Rect(guiPoint.x - 50.0f, guiPoint.y - 40, 100, 20);
            //draw box at rect position with current waypoint name
            GUI.Box(rect, pathnode.gameObject.name);
            Handles.EndGUI(); //end GUI block
        }
    }
    List <PathNode> GeneratePathNode()
    {
        mRefeshIndex++;
        PathNodeEditor.sMaxID = 0;
        List <PathNode> pathnodes = new List <PathNode>();

        Debug.LogError("transform.childCount " + transform.childCount);
        for (int i = 0; i < transform.childCount; i++)
        {
            Transform      trans      = transform.GetChild(i);
            PathNodeEditor nodeeditor = trans.GetComponent <PathNodeEditor>();
            if (nodeeditor == null)
            {
                Debug.LogError("Child is not PathNodeEditor please check.");
                continue;
            }
            PathNode head = nodeeditor.GeneratePathNode(i + 1, mRefeshIndex, pathnodes);
        }
        return(pathnodes);
    }
    public void LoadBinary(string pathfile)
    {
        PathNodeManager.instance.LoadBinary(pathfile);
        Dictionary <int, PathNodeEditor> dict_nodeeditor = new Dictionary <int, PathNodeEditor>();
        List <PathNodeEditor>            lst_editor      = new List <PathNodeEditor>();

        for (int i = 0; i < PathNodeManager.instance.mListNodes.Count; i++)
        {
            PathNode       node       = PathNodeManager.instance.mListNodes[i];
            GameObject     obj        = new GameObject("node");
            PathNodeEditor nodeeditor = obj.AddComponent <PathNodeEditor>();
            // nodeeditor.mId = node.mId;
            nodeeditor.mGroupID           = node.mGroupID;
            nodeeditor.mValue             = node.mValue;
            nodeeditor.transform.position = node.mPosition;
            nodeeditor.transform.rotation = node.mRotation;
            if (dict_nodeeditor.ContainsKey(nodeeditor.mGroupID))
            {
                PathNodeEditor root = dict_nodeeditor[nodeeditor.mGroupID];
                nodeeditor.transform.parent = root.transform;
            }
            else
            {
                nodeeditor.transform.parent = this.transform;
                dict_nodeeditor.Add(nodeeditor.mGroupID, nodeeditor);
            }
            lst_editor.Add(nodeeditor);
        }

        for (int i = 0; i < lst_editor.Count; i++)
        {
            PathNodeEditor nodeeditor = lst_editor[i];
            PathNode       node       = PathNodeManager.instance.mListNodes[i];
            for (int j = 0; j < node.mLinkID.Count; j++)
            {
                PathNodeEditor link_nodeeditor = lst_editor[node.mLinkID[j]];
                nodeeditor.mListNode.Add(link_nodeeditor);
            }
        }
    }