Exemplo n.º 1
0
        public void InitWithFTNodeCfg(FTNodeCfg cfg)
        {
            if (cfg == null)
            {
                Debug.LogError("failed init FTNode because cfg is null");
                return;
            }

            string[] nodeInfo = cfg.path.Split('/');
            if (nodeInfo == null || nodeInfo.Length < 2)
            {
                Debug.LogError("failed init FTNode because path format is not right > " + cfg.path);
                return;
            }

            category = nodeInfo[0];
            name     = nodeInfo[nodeInfo.Length - 1];

            properties.Clear();
            if (cfg.defaultProperties != null && cfg.defaultProperties.Length > 0)
            {
                for (int i = 0; i < cfg.defaultProperties.Length; ++i)
                {
                    FTNodeProperty np = cfg.defaultProperties[i].Clone();
                    properties.Add(np);
                }
            }
        }
Exemplo n.º 2
0
    public FTNodeProperty Clone()
    {
        FTNodeProperty np = new FTNodeProperty();

        np.valueType = this.valueType;
        np.key       = this.key;
        np.value     = this.value;
        return(np);
    }
Exemplo n.º 3
0
        public override void OnInspectorGUI()
        {
            serializedObject.Update();

            // if (NodeEditorWindow.mode == NodeEditorMode.Runtime)
            //     EditorGUI.BeginDisabledGroup(true);
            // else
            //     EditorGUI.BeginChangeCheck();

            EditorGUILayout.LabelField("ID", EditorStyles.boldLabel);
            EditorGUILayout.LabelField(FTNode.id);

            DrawName();

            EditorGUILayout.Space();
            EditorGUILayout.LabelField("Category", EditorStyles.boldLabel);
            EditorGUILayout.LabelField(FTNode.category);

            EditorGUILayout.Space();
            EditorGUILayout.LabelField("Description", EditorStyles.boldLabel);
            FTNode.description = EditorGUILayout.TextArea(FTNode.description, GUILayout.Height(70f));

            EditorGUILayout.Space();
            EditorGUILayout.BeginHorizontal();
            {
                EditorGUILayout.LabelField("Properties", EditorStyles.boldLabel);

                if (GUILayout.Button("Add"))
                {
                    FTNodeProperty prop = new FTNodeProperty();
                    prop.Key         = "key";
                    prop.StringValue = "value";
                    prop.ValueType   = FTNodeProperty.StringType;
                    FTNode.properties.Add(prop);
                }
            }
            EditorGUILayout.EndHorizontal();

            DrawProperties();

            // if (NodeEditorWindow.mode == NodeEditorMode.Runtime)
            // {
            //     EditorGUI.EndDisabledGroup();
            //     DrawRuntimeInfo();
            // }
            // else
            // {
            //     if (EditorGUI.EndChangeCheck())
            //         AutoSaveAsset();
            // }

            serializedObject.ApplyModifiedProperties();
        }
Exemplo n.º 4
0
        public static B3TreeData ToB3TreeData(FTGraph btGraph)
        {
            if (btGraph == null)
            {
                Debug.LogError("cant ToB3TreeData because btGraph is null");
                return(null);
            }

            B3TreeData b3Tree = new B3TreeData();

            b3Tree.id = btGraph.id;
            // b3Tree.root = btGraph.root.id;
            b3Tree.title = btGraph.title;
            // b3Tree.description = btGraph.description;

            for (int i = 0; i < btGraph.nodes.Count; ++i)
            {
                if ((btGraph.nodes[i] is FTNode) == false)
                {
                    continue;
                }

                FTNode FTNode = (FTNode)btGraph.nodes[i];

                B3NodeInfo b3NodeInfo = new B3NodeInfo();

                if (b3Tree.nodes.ContainsKey(FTNode.id))
                {
                    UnityEditor.EditorUtility.DisplayDialog("Error", $"CHECK: exist same id AI node > {FTNode.id} - {FTNode.name}", "OK");
                    return(null);
                }

                b3Tree.nodes[FTNode.id] = b3NodeInfo;

                Dictionary <string, object> dictNode = new Dictionary <string, object>();
                b3NodeInfo.id       = FTNode.id;
                b3NodeInfo.name     = FTNode.name;
                b3NodeInfo.category = FTNode.category;
                // b3NodeInfo.description = FTNode.description;
                // b3NodeInfo.display["x"] = (int)FTNode.position.x;
                // b3NodeInfo.display["y"] = (int)FTNode.position.y;

                if (FTNode.properties != null)
                {
                    for (int j = 0; j < FTNode.properties.Count; ++j)
                    {
                        FTNodeProperty prop = FTNode.properties[j];
                        b3NodeInfo.properties.Add(prop.Key, prop.Value);
                    }
                }

                for (int j = 0; j < FTNode.ChildCount; ++j)
                {
                    FTNode childFTNode = FTNode.GetChildNode(j);
                    if (childFTNode == null)
                    {
                        UnityEditor.EditorUtility.DisplayDialog("Error", $"CHECK: exist null child AI node > {FTNode.id} - {FTNode.name}", "OK");
                        return(null);
                    }
                    if (btGraph.IsExistFTNode(childFTNode.id) == false)
                    {
                        UnityEditor.EditorUtility.DisplayDialog("Error", $"CHECK: cant find child AI node > {FTNode.id} - {FTNode.name} - child: {childFTNode.id}", "OK");
                        return(null);
                    }
                    b3NodeInfo.children.Add(childFTNode.id);
                }
            }

            // custom value
            // b3Tree.display.camera_x = 960;
            // b3Tree.display.camera_y = 508;
            // b3Tree.display.camera_z = 1;

            return(b3Tree);
        }
Exemplo n.º 5
0
        private void DrawProperties()
        {
            FTNodeCfg nodeCfg = BTEditorDefine.GetFTNodeCfg(FTNode.name);

            for (int i = 0; i < FTNode.properties.Count; ++i)
            {
                FTNodeProperty    prop = FTNode.properties[i];
                bool              isDefaultProperty = IsDefaultProperty(nodeCfg, prop.Key);
                FTNodePropertyCfg propCfg           = BTEditorDefine.GetFTNodePropertyCfg(prop.Key, FTNode.category);

                EditorGUILayout.BeginHorizontal();
                {
                    EditorGUI.BeginDisabledGroup(isDefaultProperty);
                    {
                        prop.Key = EditorGUILayout.TextField(prop.Key);

                        int lastSelectTypeIndex = Array.IndexOf(FTNodeProperty.SupportTypes, prop.ValueType);
                        int selectTypeIndex     = EditorGUILayout.Popup(lastSelectTypeIndex, FTNodeProperty.SupportTypes);
                        prop.ValueType = FTNodeProperty.SupportTypes[selectTypeIndex];
                    }
                    EditorGUI.EndDisabledGroup();

                    if (prop.ValueType == FTNodeProperty.IntType)
                    {
                        prop.IntValue = EditorGUILayout.IntField(prop.IntValue);
                    }
                    else if (prop.ValueType == FTNodeProperty.FloatType)
                    {
                        // special
                        bool isValueDisabled = false;
                        if (FTNode.name == "CheckTargetHatred" && prop.Key == "value2")
                        {
                            if (FTNode.properties[1].Key == "compOperator" &&
                                (FTNode.properties[1].StringValue == "lessEqual" || FTNode.properties[1].StringValue == "greaterEqual"))
                            {
                                isValueDisabled = true;
                            }
                        }

                        EditorGUI.BeginDisabledGroup(isValueDisabled);
                        prop.FloatValue = EditorGUILayout.FloatField(prop.FloatValue);
                        EditorGUI.EndDisabledGroup();
                    }
                    else if (prop.ValueType == FTNodeProperty.StringType)
                    {
                        if (propCfg != null && propCfg.valueType == FTNodePropertyCfg.ValueType.StringEnum)
                        {
                            string[] defVals   = propCfg.GetStringEnumValues();
                            int      curValIdx = Array.IndexOf(defVals, prop.StringValue);
                            if (curValIdx >= 0 && curValIdx < defVals.Length)
                            {
                                int selValIdx = EditorGUILayout.Popup(curValIdx, defVals);
                                prop.StringValue = defVals[selValIdx];
                            }
                            else
                            {
                                Debug.LogError("Failed to get value in prop cfg > " + FTNode.name + " - " + prop.StringValue);
                                prop.StringValue = EditorGUILayout.TextField(prop.StringValue);
                            }
                        }
                        else
                        {
                            prop.StringValue = EditorGUILayout.TextField(prop.StringValue);
                        }
                    }
                    else
                    {
                        Debug.LogError("not implement FTNodeProperty value type > " + prop.ValueType);
                    }

                    EditorGUI.BeginDisabledGroup(isDefaultProperty);
                    if (GUILayout.Button("Remove"))
                    {
                        FTNode.properties.Remove(prop);
                    }
                    EditorGUI.EndDisabledGroup();
                }
                EditorGUILayout.EndHorizontal();
            }
        }