Example #1
0
        public static void DrawObjArrayProp <T> (EditorProp array) where T : UnityEngine.Object
        {
            if (showArray)
            {
                StartBox(Colors.darkGray);

                //label and show
                EditorGUILayout.BeginHorizontal();
                showArray = SmallToggleButton(GUIContent.none, showArray, out _);
                Label(new GUIContent(string.Format("<b>{0}:</b>", array.displayName)));

                if (GUIUtils.SmallButton(new GUIContent("", "Add Element"), Colors.green, Colors.black))
                {
                    array.AddNew().SetValue((UnityEngine.Object)null);
                }
                EditorGUILayout.EndHorizontal();

                int newVal = array.arraySize;
                if (newVal != 0)
                {
                    Space();
                }

                int deleteIndex = -1;
                //array elements

                for (int i = 0; i < newVal; i++)
                {
                    EditorGUILayout.BeginHorizontal();

                    if (SmallDeleteButton())
                    {
                        deleteIndex = i;
                    }
                    DrawProp(array[i]);
                    EditorGUILayout.EndHorizontal();
                }
                if (deleteIndex != -1)
                {
                    array.DeleteAt(deleteIndex, "manual array prop delete");
                }

                EndBox(newVal == 0 ? 0 : 1);
            }
            else
            {
                EditorGUILayout.BeginHorizontal();
                showArray = SmallToggleButton(GUIContent.none, showArray, out _);
                Label(new GUIContent(string.Format("<b>{0}</b>", array.displayName)));
                EditorGUILayout.EndHorizontal();
            }
        }
Example #2
0
        bool DrawPackParameters(EditorProp parameters)
        {
            bool anyChange = false;

            GUIUtils.StartBox();
            GUIUtils.Label(new GUIContent("<b>Asset Object Default Parameters:</b>"));
            GUIUtils.StartBox(Colors.darkGray);
            string dupName;

            if (parameters.ContainsDuplicateNames(out dupName))
            {
                GUIUtils.HelpBox(string.Format("\nMultiple parameters named:\n\t<i>'{0}'</i>\n", dupName), MessageType.Error);
            }
            GUIUtils.StartBox(1);
            int deleteParamIndex = -1;

            for (int i = 0; i < parameters.arraySize; i++)
            {
                UnityEngine.GUI.enabled = i != 0;
                EditorGUILayout.BeginHorizontal();
                if (GUIUtils.SmallDeleteButton())
                {
                    deleteParamIndex = i;
                }
                if (DrawPackParameter(parameters[i]))
                {
                    anyChange = true;
                }
                EditorGUILayout.EndHorizontal();
                UnityEngine.GUI.enabled = true;
            }
            if (deleteParamIndex >= 0)
            {
                parameters.DeleteAt(deleteParamIndex, "manual parameter delete");
                anyChange = true;
            }
            GUIUtils.BeginIndent();
            if (GUIUtils.Button(new GUIContent("Add Parameter"), GUIStyles.miniButton, Colors.green, Colors.black, true))
            {
                parameters.AddNew("New Parameter");
                anyChange = true;
            }
            GUIUtils.EndIndent();
            GUIUtils.EndBox(1);
            GUIUtils.EndBox();
            GUIUtils.EndBox();
            return(anyChange);
        }
Example #3
0
        static void UpdateParametersIfDifferentFromDefaults(EditorProp parameters, EditorProp defaultParams, bool debug)
        {
            int aoParametersCount  = parameters.arraySize;
            int defParametersCount = defaultParams.arraySize;

            Func <EditorProp, string> GetParamName = (EditorProp parameter) => parameter[CustomParameterEditor.nameField].stringValue;

            //check for parameters to delete
            for (int i = aoParametersCount - 1; i >= 0; i--)
            {
                string name        = GetParamName(parameters[i]);
                bool   inDefParams = false;
                for (int d = 0; d < defParametersCount; d++)
                {
                    if (GetParamName(defaultParams[d]) == name)
                    {
                        inDefParams = true;
                        break;
                    }
                }
                if (!inDefParams)
                {
                    if (debug)
                    {
                        Debug.Log("Deleting param: " + name);
                    }
                    parameters.DeleteAt(i, "deleting different params");
                }
            }
            // Debug.Log("finished deletes");

            aoParametersCount = parameters.arraySize;



            //check for parameters that need adding
            for (int i = 0; i < defParametersCount; i++)
            {
                var    defParam     = defaultParams[i];
                string defParamName = GetParamName(defParam);


                bool inParams = false;
                for (int p = 0; p < aoParametersCount; p++)
                {
                    if (GetParamName(parameters[p]) == defParamName)
                    {
                        inParams = true;
                        break;
                    }
                }
                if (!inParams)
                {
                    if (debug)
                    {
                        Debug.Log("adding param: " + defParamName);
                    }
                    CustomParameterEditor.CopyParameter(parameters.AddNew(), defParam);
                }
            }

            aoParametersCount = parameters.arraySize;


            // Debug.Log("finished Adds");

            //reorder to same order


            EditorProp temp = null;

            for (int d = 0; d < defParametersCount; d++)
            {
                string defParamName = GetParamName(defaultParams[d]);
                var    parameter    = parameters[d];
                if (GetParamName(parameter) == defParamName)
                {
                    continue;
                }

                if (debug)
                {
                    Debug.Log("moving param: " + GetParamName(parameter));
                }

                EditorProp trueParam = null;
                //for (int p = d + 1; p < c_p; p++) {
                for (int p = 0; p < aoParametersCount; p++)
                {
                    trueParam = parameters[p];
                    if (GetParamName(trueParam) == defParamName)
                    {
                        break;
                    }
                }

                if (trueParam == null)
                {
                    if (debug)
                    {
                        Debug.LogError("couldnt find: " + defParamName);
                    }
                }
                //put the current one in temp

                if (temp == null)
                {
                    //make extra temp parameeter
                    temp = parameters.AddNew();
                }

                // Debug.Log("put in temp");
                CustomParameterEditor.CopyParameter(temp, parameter);
                //place the real param in the current
                // Debug.Log("put in current");
                CustomParameterEditor.CopyParameter(parameter, trueParam);


                //place temp in old param that was moved
                // Debug.Log("put in temp 2");

                CustomParameterEditor.CopyParameter(trueParam, temp);
            }

            if (temp != null)
            {
                //delete temp parameter
                parameters.DeleteAt(parameters.arraySize - 1, "deleting temp param");
            }

            //check type changes
            Func <EditorProp, int> GetParamType = (EditorProp parameter) => parameter[CustomParameterEditor.typeField].intValue;

            for (int i = 0; i < defParametersCount; i++)
            {
                if (GetParamType(parameters[i]) != GetParamType(defaultParams[i]))
                {
                    if (debug)
                    {
                        Debug.Log("changing: " + GetParamName(parameters[i]) + " from " + GetParamType(parameters[i]) + " to " + GetParamType(defaultParams[i]));
                    }
                    CustomParameterEditor.CopyParameter(parameters[i], defaultParams[i]);
                }
            }
        }