Exemplo n.º 1
0
        public override void OnInspectorGUI()
        {
            serializedObject.Update();

            EditorGUILayout.LabelField(target.name, EditorStyles.boldLabel);
            EditorGUILayout.PropertyField(ID);
            //EditorGUILayout.PropertyField(internalData);
            EditorGUILayout.Space();


            Reo_List_Tasks.DoLayoutList();

            if (Reo_List_Tasks.index != -1)
            {
                Reo_List_Transitions.index = -1;
            }

            Reo_List_Transitions.DoLayoutList();

            if (Reo_List_Transitions.index != -1)
            {
                Reo_List_Tasks.index = -1;
            }


            var indexTasks = Reo_List_Tasks.index;
            var indexTrans = Reo_List_Transitions.index;

            if (indexTasks != -1)
            {
                var element = tasks.GetArrayElementAtIndex(indexTasks);

                if (element != null && element.objectReferenceValue != null)
                {
                    var asset = element.objectReferenceValue;

                    EditorGUILayout.BeginVertical(EditorStyles.helpBox);

                    EditorGUILayout.LabelField("Task: " + asset.name, EditorStyles.boldLabel);

                    EditorGUILayout.BeginHorizontal();
                    {
                        asset.name = EditorGUILayout.TextField("Name", asset.name);
                        element.serializedObject.ApplyModifiedProperties();
                        EditorUtility.SetDirty(asset);

                        if (GUILayout.Button(new GUIContent("R", "Update the Asset name"), GUILayout.Width(20)))
                        {
                            AssetDatabase.SaveAssets();
                            EditorGUIUtility.PingObject(asset); //Final way of chaning the name of the asset... dirty but it works
                        }
                    }
                    EditorGUILayout.EndHorizontal();

                    MTools.DrawObjectReferenceInspector(element);
                    EditorGUILayout.EndVertical();
                }
            }

            if (indexTrans != -1)
            {
                var element  = transitions.GetArrayElementAtIndex(indexTrans);
                var decision = element.FindPropertyRelative("decision");

                if (decision != null && decision.objectReferenceValue != null)
                {
                    EditorGUILayout.BeginVertical(EditorStyles.helpBox);
                    EditorGUILayout.LabelField("Decision: " + decision.objectReferenceValue.name, EditorStyles.boldLabel);

                    var asset = decision.objectReferenceValue;

                    EditorGUILayout.BeginHorizontal();
                    {
                        asset.name = EditorGUILayout.TextField("Name", asset.name);
                        decision.serializedObject.ApplyModifiedProperties();
                        EditorUtility.SetDirty(asset);

                        if (GUILayout.Button(new GUIContent("R", "Update the Asset name"), GUILayout.Width(20)))
                        {
                            AssetDatabase.SaveAssets();
                            EditorGUIUtility.PingObject(asset); //Final way of chaning the name of the asset... dirty but it works
                        }
                    }
                    EditorGUILayout.EndHorizontal();

                    MTools.DrawObjectReferenceInspector(decision);
                    EditorGUILayout.EndVertical();
                }
            }

            serializedObject.ApplyModifiedProperties();
        }