Ejemplo n.º 1
0
 public bool ContainParam(SWParam param)
 {
     foreach (var item in paramList)
     {
         if (item.name == param.name)
         {
             return(true);
         }
     }
     return(false);
 }
Ejemplo n.º 2
0
        protected void Factor_CustomParamCreation()
        {
            paramNameLastDeleted = "";
            DrawModuleTitle("Custom Parameters");
            Rect lastRect = GUILayoutUtility.GetLastRect();
            Rect rect     = new Rect(lastRect.x, lastRect.y, lastRect.width + SWGlobalSettings.FieldWidth, lastRect.height + rightUpUnitHeight);

            Tooltip_Rec(SWTipsText.Right_CustomParam, rect);

            paramName = EditorGUILayout.TextField(paramName, GUILayout.Width(100));


            GUILayout.BeginHorizontal();
            if (GUILayout.Button("New Float", GUILayout.Width(80)))
            {
                paramName = SWRegex.NameLegal(paramName);
                if (ParamNameUnique(paramName))
                {
                    SWParam pa = new SWParam();
                    pa.type = SWParamType.FLOAT;
                    pa.name = paramName;
                    SWWindowMain.Instance.data.paramList.Add(pa);
                }
                paramName = "";
            }
            if (GUILayout.Button("New Range", GUILayout.Width(80)))
            {
                paramName = SWRegex.NameLegal(paramName);
                if (ParamNameUnique(paramName))
                {
                    SWParam pa = new SWParam();
                    pa.type = SWParamType.RANGE;
                    pa.name = paramName;
                    SWWindowMain.Instance.data.paramList.Add(pa);
                }
                paramName = "";
            }
            GUILayout.EndHorizontal();


            int toDeleteId = -1;

            for (int i = 0; i < SWWindowMain.Instance.data.paramList.Count; i++)
            {
                //GUILayout.Space (SWGlobalSettings.UIGap);
                var item = SWWindowMain.Instance.data.paramList[i];
                GUILayout.BeginHorizontal();
                float nameWidth = 64f;
                GUILayout.Label(item.name, SWEditorUI.Style_Get(SWCustomStyle.eTxtSmallLight), GUILayout.Width(nameWidth));
                if (item.type == SWParamType.RANGE)
                {
                    var f = EditorGUILayout.FloatField(item.defaultValue, GUILayout.Width(30));
                    if (f != item.defaultValue)
                    {
                        item.defaultValue = f;
                        SWProperties.SetFloat(item.name, item.defaultValue);
                    }

                    f = GUILayout.HorizontalSlider(item.defaultValue, item.min, item.max, GUILayout.Width(40));
                    if (f != item.defaultValue)
                    {
                        item.defaultValue = f;
                        SWProperties.SetFloat(item.name, item.defaultValue);
                    }


                    GUILayout.Label("Min", SWEditorUI.Style_Get(SWCustomStyle.eTxtSmallLight), GUILayout.Width(22));
                    item.min = EditorGUILayout.FloatField("", item.min, GUILayout.Width(25));
                    GUILayout.Label("Max", SWEditorUI.Style_Get(SWCustomStyle.eTxtSmallLight), GUILayout.Width(26));
                    item.max = EditorGUILayout.FloatField("", item.max, GUILayout.Width(25));
                }
                if (item.type == SWParamType.FLOAT)
                {
                    var f = EditorGUILayout.FloatField(item.defaultValue, GUILayout.Width(rightupWidth - nameWidth - SWGlobalSettings.UIGap * 2 - 18 - 2));
                    if (f != item.defaultValue)
                    {
                        item.defaultValue = f;
                        SWProperties.SetFloat(item.name, item.defaultValue);
                    }
                }

                lastRect = GUILayoutUtility.GetLastRect();

                if (GUI.Button(new Rect(position.width - 33 - SWGlobalSettings.UIGap, lastRect.y, 18, 17), "X"))
                {
                    toDeleteId = i;
                }
                GUILayout.EndHorizontal();
            }
            if (toDeleteId >= 0)
            {
                paramNameLastDeleted = SWWindowMain.Instance.data.paramList[toDeleteId].name;
                SWWindowMain.Instance.data.paramList.RemoveAt(toDeleteId);
            }
        }