示例#1
0
    void ShowSpriteSettings()
    {
        IPackableControl cont = (IPackableControl)control;

        // Get the info for this state/element:
        stateInfo = cont.GetStateElementInfo(curState);

        // Put up a texture drop box:
        // Load the texture:
        if (stateInfo.stateObj.frameGUIDs.Length < 1)
        {
            stateInfo.tex = null;
        }
        else
        {
            stateInfo.tex = (Texture2D)AssetDatabase.LoadAssetAtPath(AssetDatabase.GUIDToAssetPath(stateInfo.stateObj.frameGUIDs[0]), typeof(Texture2D));
        }


        BeginMonitorChanges();
        // Select the texture for the state:
#if UNITY_3_4 || UNITY_3_5 || UNITY_3_6 || UNITY_3_7 || UNITY_3_8 || UNITY_3_9
        stateInfo.tex = (Texture2D)EditorGUILayout.ObjectField(stateNames[curState], stateInfo.tex, typeof(Texture2D), false);
#else
        stateInfo.tex = (Texture2D)EditorGUILayout.ObjectField(stateNames[curState], stateInfo.tex, typeof(Texture2D));
#endif
        EndMonitorChanges();


        // Re-assign the state info to the control:
        // If we have an available frame, assign the new GUID
        if (stateInfo.stateObj.frameGUIDs.Length > 0)
        {
            stateInfo.stateObj.frameGUIDs[0] = AssetDatabase.AssetPathToGUID(AssetDatabase.GetAssetPath(stateInfo.tex));
        }         // Else only create a new GUID element if the selection is non-null:
        else if (stateInfo.tex != null)
        {
            stateInfo.stateObj.frameGUIDs    = new string[1];
            stateInfo.stateObj.frameGUIDs[0] = AssetDatabase.AssetPathToGUID(AssetDatabase.GetAssetPath(stateInfo.tex));
        }         // Else, don't do anything. Period.

        transitions = stateInfo.transitions;
    }
    void ShowSpriteSettings()
    {
        IPackableControl cont = (IPackableControl)control;

        // Get the info for this state/element:
        stateInfo = cont.GetStateElementInfo(curState);


        // See if the sprite timeline is available:
        if (ste == null)
        {
            System.Reflection.Assembly asm = System.Reflection.Assembly.GetAssembly(typeof(UICtlEditor));
            System.Type steType            = asm.GetType("SpriteTimeline");
            if (steType != null)
            {
                ste = (ISTE)System.Activator.CreateInstance(steType);
                ste.Setup(position, 0);
            }
        }

        // NOW see if the timeline is available:
        if (ste != null)
        {
            ste.SetCurAnim(curState);
            needRepaint = ste.STEOnGUI(-(20f + height), out textureAreaBottom);
        }
        else
        {
            // Put up a texture drop box:
            // Load the texture:
            if (stateInfo.stateObj.frameGUIDs.Length < 1)
            {
                stateInfo.stateObj.frameGUIDs = new string[1] {
                    ""
                };
            }
            stateInfo.tex = (Texture2D)AssetDatabase.LoadAssetAtPath(AssetDatabase.GUIDToAssetPath(stateInfo.stateObj.frameGUIDs[0]), typeof(Texture2D));


            BeginMonitorChanges();
#if UNITY_IPHONE && !(UNITY_3_0 || UNITY_3_1 || UNITY_3_2 || UNITY_3_3 || UNITY_3_4 || UNITY_3_5 || UNITY_3_6 || UNITY_3_7 || UNITY_3_8 || UNITY_3_9)
            // Draw a "clear" button:
            if (GUI.Button(new Rect(clearRect.x, clearRect.y + height, clearRect.width, clearRect.height), "X"))
            {
                stateInfo.tex = null;
            }

            // Select the texture for the state:
            stateInfo.tex     = (Texture2D)EditorGUI.ObjectField(tempRect, stateInfo.tex, typeof(Texture2D));
            textureAreaBottom = tempRect.yMax + ctlVirtSpace;
#else
            // Select the texture for the state:
        #if UNITY_3_4 || UNITY_3_5 || UNITY_3_6 || UNITY_3_7 || UNITY_3_8 || UNITY_3_9
            stateInfo.tex = (Texture2D)EditorGUILayout.ObjectField(stateNames[curState], stateInfo.tex, typeof(Texture2D), false);
        #else
            stateInfo.tex = (Texture2D)EditorGUILayout.ObjectField(stateNames[curState], stateInfo.tex, typeof(Texture2D));
        #endif
            textureAreaBottom = 0;             // This tells us to use Layout.
#endif

            // Handle drag and drop from an outside source:
            EventType eventType = Event.current.type;
            if (eventType == EventType.DragUpdated || eventType == EventType.DragPerform)
            {
                // Validate what is being dropped:
                if (DragAndDrop.objectReferences[0] is Texture2D)
                {
                    // Show a copy icon on the drag
                    DragAndDrop.visualMode = DragAndDropVisualMode.Copy;

                    if (eventType == EventType.DragPerform)
                    {
                        DragAndDrop.AcceptDrag();
                        stateInfo.tex = (Texture2D)DragAndDrop.objectReferences[0];
                        needRepaint   = true;
                    }

                    Event.current.Use();
                }
            }

            EndMonitorChanges();

            // Re-assign the state info to the control:
            stateInfo.stateObj.frameGUIDs[0] = AssetDatabase.AssetPathToGUID(AssetDatabase.GetAssetPath(stateInfo.tex));
        }
    }