Ejemplo 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);
                }
            }
        }
Ejemplo n.º 2
0
 private bool IsDefaultProperty(FTNodeCfg nodeCfg, string key)
 {
     if (nodeCfg == null)
     {
         return(false);
     }
     if (nodeCfg.defaultProperties == null)
     {
         return(false);
     }
     for (int i = 0; i < nodeCfg.defaultProperties.Length; ++i)
     {
         if (nodeCfg.defaultProperties[i].Key == key)
         {
             return(true);
         }
     }
     return(false);
 }
Ejemplo n.º 3
0
        public override void OnOpen()
        {
            if (nodeSearchField == null)
            {
                nodeSearchField = new AutocompleteSearchField();
                nodeSearchField.onInputChanged = OnNodeSearchFieldInputChanged;
                nodeSearchField.onConfirm      = OnNodeSearchFieldConfirm;
            }

            nodeSearchPaths.Clear();
            for (int i = 0; i < BTEditorDefine.NodeCfgs.Count; ++i)
            {
                FTNodeCfg cfgNode = BTEditorDefine.NodeCfgs[i];
                nodeSearchPaths.Add(cfgNode.path);
            }

            toolbarRect = new Rect(0, 0, Screen.width, TOOLBAR_HEIGHT);
            // NodeEditorWindow.current.blockMouseAreas.Add(toolbarRect);
        }
Ejemplo n.º 4
0
        public void InitWhenAddFromGraph(FTNodeCfg cfg)
        {
            id = BTEditorUtils.NewGuid();

            InitWithFTNodeCfg(cfg);
        }
Ejemplo 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();
            }
        }