Example #1
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();
            }
        }