コード例 #1
0
                public static object PropertyField(object obj, GUIContent label, ref bool dataChanged, GUIStyle style, params GUILayoutOption[] options)
                {
                    StateRef state = (StateRef)obj;

                    if (label == null)
                    {
                        label = new GUIContent();
                    }

                    label.text += " (" + state + ")";

                    bool editorCollapsed = !EditorGUILayout.Foldout(!state._editorCollapsed, label);

                    if (editorCollapsed != state._editorCollapsed)
                    {
                        state._editorCollapsed = editorCollapsed;
                        dataChanged            = true;
                    }

                    if (!editorCollapsed)
                    {
                        int origIndent = EditorGUI.indentLevel;
                        EditorGUI.indentLevel++;


                        EditorGUI.BeginChangeCheck();
                        eType type = (eType)EditorGUILayout.EnumPopup("Link Type", state.IsInternal() ? eType.Internal : eType.External);
                        if (EditorGUI.EndChangeCheck())
                        {
                            //If type has changed create a new ref with file set to null if internal or a blank asset ref if external.
                            state       = new StateRef(type == eType.External ? -1 : 0, state.GetParentStateMachine());
                            dataChanged = true;
                        }

                        switch (type)
                        {
                        case eType.Internal:
                        {
                            StateMachine stateMachine = state.GetParentStateMachine();
                            if (stateMachine != null)
                            {
                                int stateId = state.GetStateID();

                                //If changed state id create new state ref
                                if (DrawStateNamePopUps(stateMachine._states, ref stateId))
                                {
                                    state       = new StateRef(stateId, stateMachine);
                                    dataChanged = true;
                                }
                            }
                        }
                        break;

                        case eType.External:
                        {
                            TextAsset asset = EditorGUILayout.ObjectField("File", state.GetExternalFile()._editorAsset, typeof(TextAsset), false) as TextAsset;

                            //If asset changed update GUIDS
                            if (state.GetExternalFile()._editorAsset != asset)
                            {
                                state       = new StateRef(asset, -1, state.GetParentStateMachine());
                                dataChanged = true;
                            }

                            if (asset != null)
                            {
                                StateMachine stateMachines = Serializer.FromFile <StateMachine>(AssetDatabase.GetAssetPath(asset));
                                int          stateId       = state.GetStateID();

                                if (DrawStateNamePopUps(stateMachines._states, ref stateId))
                                {
                                    state       = new StateRef(asset, stateId, state.GetParentStateMachine());
                                    dataChanged = true;
                                }
                            }
                        }
                        break;
                        }

                        EditorGUI.indentLevel = origIndent;
                    }

                    return(state);
                }