Esempio n. 1
0
        public void Show(InstructionSet set)
        {
            titleContent = new GUIContent("Instructions");
            _set         = set;

            BuildTree();

            Show();
        }
Esempio n. 2
0
        // TODO: listen for on set added/removed

        public static void InstructionSetChanged(InstructionSet set)
        {
            foreach (var data in _popups)
            {
                if (data.Set == set)
                {
                    data.FlyoutNames = null;
                }
                data.RootNames = null;
            }
        }
Esempio n. 3
0
        private void Remove(InstructionSet set, int index)
        {
            using (new UndoScope(set))
            {
                var instruction = set.Instructions[index];
                if (instruction != null)
                {
                    Undo.DestroyObjectImmediate(instruction);
                }

                set.Instructions.RemoveAt(index);

                AssetDatabase.ImportAsset(AssetDatabase.GetAssetPath(set));
                InstructionDrawer.InstructionSetChanged(set);
            }
        }
Esempio n. 4
0
        public static Instruction Draw(Rect position, InstructionSet set, Instruction currentInstruction, GUIContent label)
        {
            if (label != null)
            {
                position = EditorGUI.PrefixLabel(position, label);
            }

            var popup = GetPopup(set);
            var names = popup.GetRootNames();
            var index = popup.GetIndex(currentInstruction);
            var left  = currentInstruction != null ? new Rect(position.x, position.y, position.width * 0.5f, EditorGUIUtility.singleLineHeight) : position;

            using (var changes = new EditorGUI.ChangeCheckScope())
            {
                index = EditorGUI.Popup(left, index, names);

                if (changes.changed)
                {
                    currentInstruction = popup.GetInstruction(index);
                }
            }

            if (currentInstruction != null)
            {
                var edit  = new Rect(left.xMax + 5, position.y, (position.width - left.width - 10) * 0.5f, EditorGUIUtility.singleLineHeight);
                var clear = new Rect(edit.xMax + 5, position.y, edit.width, edit.height);

                if (GUI.Button(edit, EditorHelper.EditContent))
                {
                    InstructionBreadcrumbs.Edit(currentInstruction);
                }

                if (GUI.Button(clear, EditorHelper.ClearContent))
                {
                    currentInstruction = null;
                }
            }

            return(currentInstruction);
        }
Esempio n. 5
0
        public static Instruction Create(InstructionSet set, SerializedProperty property, Type type)
        {
            var existingNames = set.Instructions.Select(i => i.name).ToArray();
            var instruction   = ScriptableObject.CreateInstance(type) as Instruction;

            instruction.name      = ObjectNames.GetUniqueName(existingNames, type.Name);
            instruction.hideFlags = HideFlags.HideInHierarchy;
            instruction.Set       = set;

            set.Instructions.Add(instruction);

            if (property != null)
            {
                property.serializedObject.Update();
                property.objectReferenceValue = instruction;
            }

            AssetDatabase.AddObjectToAsset(instruction, set);
            AssetDatabase.ImportAsset(AssetDatabase.GetAssetPath(set));

            InstructionSetChanged(set);

            return(instruction);
        }
Esempio n. 6
0
 private static PopupData GetPopup(InstructionSet set)
 {
     return(GetPopups().Single(p => p.Set == set));
 }
Esempio n. 7
0
 private void Design(InstructionSet set)
 {
     CreateInstance <InstructionSetWindow>().Show(set);
 }