Ejemplo n.º 1
0
            static void HierarchyWindowItemOnGUI(int instanceID, Rect selectionRect)
            {
                //Debug.Log(Event.current.type + ":" + EditorUtility.InstanceIDToObject(instanceID).name);
                //bool firstEvent = false;
                EventType eventType = Event.current.type;

                if (eventType == EventType.Used)
                {
                    //eventType = previousEventType;
                }
                else
                {
                    if (eventType != previousEventType)
                    {
                        //firstEvent = true;
                    }
                    previousEventType = eventType;
                }

                if (eventType == EventType.Repaint)
                {
                    if (style == null)
                    {
                        Texture2D tex = new Texture2D(4, 4);
                        Color     col = new Color(0.3f, 0.5f, 1.0f, 0.3f);
                        for (int y = 0; y < tex.height; y++)
                        {
                            for (int x = 0; x < tex.width; x++)
                            {
                                tex.SetPixel(x, y, col);
                            }
                        }
                        tex.Apply();
                        style      = new GUIStyle();
                        style.name = "dropTarget";
                        style.normal.background = tex;
                    }
                    if (dragging && (targetDirection != null) && (targetInstanceID == instanceID))
                    {
                        //targetRect = new Rect(0.0f, 0.0f, 64.0f, 64.0f);
                        //GUI.depth = 1;
                        GUI.Box(targetRect, GUIContent.none, style);
                    }
                }

                // ドラッグ中の処理
                if (eventType == EventType.DragUpdated)
                {
                    dragging   = true;
                    acceptable = false;
                    foreach (var obj in DragAndDrop.objectReferences)
                    {
                        if (IsAcceptable(obj))
                        {
                            acceptable = true;
                        }
#if true
                        else
                        {
                            // 他の型がまじってたら処理しない。
                            acceptable = false;
                            break;
                        }
#endif
                    }
                    targetDirection = null;
                    if (acceptable)
                    {
                        targetDirection = CheckMousePosition(selectionRect);
                        if (targetDirection != null)
                        {
                            // drag受け入れ可の場合カーソル形状を変更。
                            DragAndDrop.visualMode      = DragAndDropVisualMode.Link;
                            DragAndDrop.activeControlID = instanceID;
                            //Event.current.Use();
                            targetInstanceID = instanceID;
                            targetRect       = selectionRect;
                            if (targetDirection < 0)
                            {
                                float y = targetRect.yMin;
                                targetRect.yMin = y - border;
                                targetRect.yMax = y + border;
                            }
                            else if (targetDirection > 0)
                            {
                                float y = targetRect.yMax;
                                targetRect.yMin = y - border;
                                targetRect.yMax = y + border;
                            }
                        }
                    }
                }

                // ドラッグ停止
                if (eventType == EventType.DragExited)
                {
                    dragging = false;
                }

                // ドロップ処理
                if (eventType == EventType.DragPerform)
                {
                    dragging = false;
                    if (targetDirection == null)
                    {
                        return;
                    }
                    if (instanceID != targetInstanceID)
                    {
                        return;
                    }
                    //Debug.Log(EditorUtility.InstanceIDToObject(instanceID).name);
                    var targetObj = EditorUtility.InstanceIDToObject(instanceID) as GameObject;
                    if (targetObj == null)
                    {
                        return;
                    }
                    DragAndDrop.AcceptDrag();
#if true
                    //Debug.Log("CheckObjectPosition:" + on);
                    Undo.RegisterFullObjectHierarchyUndo(targetObj, "");
                    MyMMLBox box = null;
                    if (targetDirection == 0)
                    {
                        box = targetObj.GetComponent <MyMMLBox>();
                    }
                    else
                    {
                        var parent = targetObj.transform.parent;
                        var index  = targetObj.transform.GetSiblingIndex() + ((targetDirection < 0) ? 0 : 1);
                        targetObj = CreateNewGameObject(parent);
                        Undo.RegisterCreatedObjectUndo(targetObj, "Create gameObject:" + targetObj.name);
                        //Undo.RegisterFullObjectHierarchyUndo(parent);
                        targetObj.transform.SetSiblingIndex(index);
                    }
                    if (box == null)
                    {
                        box = Undo.AddComponent <MyMMLBox>(targetObj);
                    }
                    foreach (var obj in DragAndDrop.objectReferences)
                    {
                        TextAsset textAsset = obj as TextAsset;
                        if (textAsset && (obj.name.EndsWith(".mml")))
                        {
                            //string path = AssetDatabase.GetAssetPath(obj);
                            //Debug.Log("path:" + path);
                            MyMMLClip clip = new MyMMLClip();
                            clip.TextC = textAsset;
                            clip.Name  = obj.name.Substring(0, obj.name.LastIndexOf('.'));
                            box.Add(clip);
                        }
                    }
#endif
                }
            }
Ejemplo n.º 2
0
 public Enumerator(MyMMLBox box)
 {
     index      = -1;
     enumerator = box.clips.GetEnumerator();
 }
Ejemplo n.º 3
0
            private void editorGUILayout_Clips(SerializedProperty property)
            {
                MyMMLBox box    = property.serializedObject.targetObject as MyMMLBox;
                bool     expand = EditorGUILayout.Foldout(property.isExpanded, "Clips");

                property.isExpanded = expand;
                if (property.isExpanded)
                {
                    EditorGUI.indentLevel++;
                    for (int i = 0; i < property.arraySize; i++)
                    {
                        var prop1 = property.GetArrayElementAtIndex(i);
                        var clip  = prop1.GetTargetFieldValue() as MyMMLClip;
                        EditorGUI.BeginChangeCheck();
                        var nameProp = prop1.FindPropertyRelative("name");
                        var name     = (nameProp == null) ? prop1.name : nameProp.stringValue;
                        if ((name == null) || (name.Length < 1))
                        {
                            name = "New Clip";
                        }
                        var elmLabel = new GUIContent(char.ToUpper(name[0]) + name.Substring(1));
                        EditorGUILayout.BeginHorizontal();
                        EditorGUILayout.PropertyField(prop1, elmLabel, false);
                        if ((syntheStation == null) || (syntheStation.LivingDead) || (Application.isPlaying))
                        {
                            EditorGUI.BeginDisabledGroup(true);
                            GUILayout.Button("Play");
                            EditorGUI.EndDisabledGroup();
                        }
                        else
                        {
                            if ((sequencer != null) && (sequencer.Playing) && (clip.Unit != null) && (sequencer.Sequence == clip.Unit.Sequence))
                            {
                                if (GUILayout.Button("Stop"))
                                {
                                    sequencer.Stop(0.0f);
                                    return;
                                }
                                sequencer.VolumeScale = clip.Volume;
                                sequencer.TempoScale  = clip.TempoScale;
                                sequencer.KeyShift    = clip.Key;
                            }
                            else
                            {
                                if (GUILayout.Button("Play"))
                                {
                                    if (!clip.Ready)
                                    {
                                        syntheStation.PrepareClip(clip, play, true);
                                    }
                                    else
                                    {
                                        play(clip);
                                    }
                                    return;
                                }
                            }
                        }
                        if (i == 0)
                        {
                            EditorGUI.BeginDisabledGroup(true);
                            GUILayout.Button("Up");
                            EditorGUI.EndDisabledGroup();
                        }
                        else
                        {
                            if (GUILayout.Button("Up"))
                            {
                                property.MoveArrayElement(i, i - 1);
                                return;
                            }
                        }
                        EditorGUILayout.Space();
                        if (GUILayout.Button("Del"))
                        {
                            prop1.isExpanded = false;
                            prop1.DeleteCommand();
                            return;
                        }
                        EditorGUILayout.EndHorizontal();
                        EditorGUILayout.Space();
                        editorGUILayout_PropertyChildren(prop1);
                        if (EditorGUI.EndChangeCheck())
                        {
                            clip.Dirty = true;
                            //clip.Flush();
                        }
                    }
                    EditorGUILayout.BeginHorizontal();
                    EditorGUILayout.Space();
                    if (GUILayout.Button("Add New Clip"))
                    {
                        Undo.RecordObject(box, "Add New Clip");
                        box.Add(new MyMMLClip());
                        return;
                    }
                    EditorGUILayout.Space();
                    EditorGUILayout.EndHorizontal();
                    EditorGUILayout.Space();
                    EditorGUI.indentLevel--;
                }
            }
Ejemplo n.º 4
0
            private void editorGUILayout_Clips(SerializedProperty property)
            {
                MyMMLBox box    = property.serializedObject.targetObject as MyMMLBox;
                bool     expand = EditorGUILayout.Foldout(property.isExpanded, "Clips");

                property.isExpanded = expand;
                if (property.isExpanded)
                {
                    Repaint();
                    //
                    EditorGUI.indentLevel++;
                    for (int i = 0; i < property.arraySize; i++)
                    {
                        SerializedProperty prop1 = property.GetArrayElementAtIndex(i);
                        MyMMLClip          clip  = getInstance(prop1) as MyMMLClip;
                        EditorGUI.BeginChangeCheck();
                        SerializedProperty nameProp = prop1.FindPropertyRelative("name");
                        string             name     = (nameProp == null) ? prop1.name : nameProp.stringValue;
                        if ((name == null) || (name.Length < 1))
                        {
                            name = "New Clip";
                        }
                        GUIContent elmLabel = new GUIContent(char.ToUpper(name[0]) + name.Substring(1));
                        EditorGUILayout.BeginHorizontal();
                        EditorGUILayout.PropertyField(prop1, elmLabel, false);
                        if ((syntheStation == null) || (syntheStation.LivingDead) || (Application.isPlaying))
                        {
                            bool old = GUI.enabled;
                            GUI.enabled = false;
                            GUILayout.Button("Play");
                            GUI.enabled = old;
                        }
                        else
                        {
                            if ((sequencer != null) && (sequencer.Playing) && (clip.Unit != null) && (sequencer.Sequence == clip.Unit.Sequence))
                            {
                                if (GUILayout.Button("Stop"))
                                {
                                    sequencer.Stop(0.0f);
                                    return;
                                }
                                sequencer.VolumeScale = clip.Volume;
                                sequencer.TempoScale  = clip.Tempo;
                                sequencer.KeyShift    = clip.Key;
                            }
                            else
                            {
                                if (GUILayout.Button("Play"))
                                {
                                    if (!clip.Valid)
                                    {
                                        syntheStation.PrepareClipBlocked(clip);
                                        if (!clip.Valid)
                                        {
                                            return;
                                        }
                                    }
                                    if (sequencer == null)
                                    {
                                        sequencer = new Synthesizer.MMLSequencer.MyMMLSequencer(syntheStation.TickFrequency);
                                        syntheStation.AddSequencer(sequencer);
                                    }
                                    else
                                    {
                                        sequencer.Stop(0.0f);
                                    }
                                    for (int j = 0; j < clip.Unit.Synthesizers.Count; j++)
                                    {
                                        sequencer.SetSynthesizer(j, clip.Unit.Synthesizers[j], clip.Unit.ToneSet, clip.Unit.ToneMap, 0xffffffffU);
                                    }
                                    sequencer.VolumeScale = clip.Volume;
                                    sequencer.TempoScale  = clip.Tempo;
                                    sequencer.KeyShift    = clip.Key;
                                    sequencer.Play(clip.Unit.Sequence, 0.0f, false);
                                    return;
                                }
                            }
                        }
                        EditorGUILayout.Space();
                        if (GUILayout.Button("Del"))
                        {
                            //Debug.Log("Delete");
                            prop1.isExpanded = false;
                            prop1.DeleteCommand();
                            return;
                        }
                        EditorGUILayout.EndHorizontal();
                        EditorGUILayout.Space();
                        editorGUILayout_PropertyChildren(prop1);
                        if (EditorGUI.EndChangeCheck())
                        {
                            clip.Dirty = true;
                            //clip.Flush();
                        }
                    }
                    EditorGUILayout.BeginHorizontal();
                    EditorGUILayout.Space();
                    if (GUILayout.Button("Add New Clip"))
                    {
                        //Debug.Log("Add New Clip");
                        Undo.RecordObject(box, "Add New Clip");
                        box.Add(new MyMMLClip());
                        return;
                    }
                    EditorGUILayout.Space();
                    EditorGUILayout.EndHorizontal();
                    EditorGUILayout.Space();
                    EditorGUI.indentLevel--;
                }
            }