Exemplo n.º 1
0
    public static void construct(SerializedProperty prop)
    {
        prop.FindPropertyRelative("name").stringValue = "Animation Set Name";
        SerializedProperty animations = prop.FindPropertyRelative("animations");

        animations.arraySize = 1;
        AnimationDrawer.construct(animations.GetArrayElementAtIndex(0));
        prop.serializedObject.ApplyModifiedProperties();
    }
Exemplo n.º 2
0
    public override void OnGUI(Rect pos, SerializedProperty prop, GUIContent label)
    {
        SerializedProperty name           = prop.FindPropertyRelative("name");
        SerializedProperty animations     = prop.FindPropertyRelative("animations");
        SerializedProperty preview        = prop.FindPropertyRelative("preview");
        SerializedProperty previewIndex   = prop.FindPropertyRelative("previewIndex");
        SerializedProperty textureAtlasID = prop.FindPropertyRelative("textureAtlasID");

        SerializedProperty folded = prop.FindPropertyRelative("folded");
        bool fold = folded.boolValue;

        EditorUtil.folder(pos.x + EditorGUI.indentLevel * 12, pos.y, folded);
        EditorUtil.textField(new Rect(pos.x + EditorUtil.buttonSize, pos.y, pos.width - 2 * EditorUtil.buttonSize, EditorUtil.height), name, !fold, "Animation Set Name");

        if (!fold)
        {
            if (EditorUtil.plus(pos.x + pos.width - EditorUtil.buttonSize, pos.y, "New Animation"))
            {
                AnimationDrawer.construct(animations.GetArrayElementAtIndex(animations.arraySize++));
            }
        }

        EditorGUI.indentLevel++;
        if (!fold)
        {
            textureAtlasID.intValue = EditorGUI.Popup(new Rect(pos.x, pos.y + 2 * EditorUtil.row, pos.width - texSize - padding, EditorUtil.height), "Tileset", textureAtlasID.intValue, TextureAtlasList.getTextureAtlasNames());

            TextureAtlas tileset = TextureAtlasList.getTextureAtlas(textureAtlasID.intValue);

            preview.intValue = Mathf.Max(-1, Mathf.Min(preview.intValue, animations.arraySize - 1));
            if (preview.intValue != -1)
            {
                SerializedProperty animation = animations.GetArrayElementAtIndex(preview.intValue);
                SerializedProperty sequence  = animation.FindPropertyRelative("tileSequence");
                SerializedProperty frameskip = animation.FindPropertyRelative("frameSkip");
                SerializedProperty lastFrame = prop.FindPropertyRelative("lastFrame");

                float time = Time.realtimeSinceStartup;
                if (time - lastFrame.floatValue < 0)
                {
                    lastFrame.floatValue = time;
                }
                else if (time - lastFrame.floatValue > frameskip.intValue * Time.fixedDeltaTime)
                {
                    previewIndex.intValue = (previewIndex.intValue + 1) % (sequence.arraySize);
                    lastFrame.floatValue  = time;
                }

                GUIContent content = getPreview(tileset, previewIndex.intValue, sequence);
                if (content == null)
                {
                    float aspect = tileset.aspect();
                    if (aspect < 1)
                    {
                        GUI.Box(new Rect(pos.x + pos.width - texSize * aspect, pos.y + EditorUtil.row, texSize * aspect, texSize), GUIContent.none, style);
                    }
                    else
                    {
                        GUI.Box(new Rect(pos.x + pos.width - texSize, pos.y + EditorUtil.row + (1 - 1 / aspect) * texSize / 2, texSize, texSize / aspect), GUIContent.none, style);
                    }
                }
                else
                {
                    GUI.Box(new Rect(pos.x + pos.width - texSize, pos.y + EditorUtil.row, texSize, texSize), content);
                }
            }

            //Draw Animations
            float   ay = EditorUtil.row + EditorUtil.texSize + EditorUtil.padding;
            float[] h  = new float[animations.arraySize];
            for (int i = 0; i < animations.arraySize; i++)
            {
                SerializedProperty anim = animations.GetArrayElementAtIndex(i);
                float animationHeight   = AnimationDrawer.calculateHeight(anim);
                //Draw Animation
                EditorGUI.PropertyField(new Rect(pos.x, pos.y + ay, pos.width, animationHeight), anim, GUIContent.none);
                //Draw Preview Button
                if (GUI.Button(new Rect(pos.x + pos.width - EditorUtil.buttonSize - AnimationDrawer.previewWidth, pos.y + ay, AnimationDrawer.previewWidth, EditorUtil.height), new GUIContent("Preview", "Preview Animation")))
                {
                    preview.intValue = i;
                }
                //Draw Delete Button
                if (EditorUtil.ex(pos.x + pos.width - EditorUtil.buttonSize, pos.y + ay, "Delete"))
                {
                    animations.DeleteArrayElementAtIndex(i);
                }

                h[i] = ay;
                ay  += animationHeight;
            }
            EditorUtil.foldLines(pos.x + EditorGUI.indentLevel * 12, pos.y, h);
        }
        EditorGUI.indentLevel--;

        prop.serializedObject.ApplyModifiedProperties();
    }