Ejemplo n.º 1
0
        public override void DisplayLayout(Rect layoutRect, GUIStyle label)
        {
            CharacterName = EditorGUILayout.TextField("Character Name", CharacterName);

            GUILayout.BeginHorizontal();
            {
                GUILayout.Label("Character Sprite", GUILayout.MaxWidth(147));
                Character = EditorGUILayout.ObjectField(Character, typeof(Sprite), false) as Sprite;
            }
            GUILayout.EndHorizontal();

            Flip = GUILayout.Toggle(Flip, "Flip");

            if (Character != null)
            {
                foldOut = EditorGUILayout.Foldout(foldOut, "Preview", true);
                if (foldOut)
                {
                    layoutRect.position = new Vector2(layoutRect.x, layoutRect.y + 70);
                    layoutRect.width    = 1000;
                    layoutRect.height   = 500;

                    layoutRect.width = Character.rect.width / (Character.rect.height / 500);
                    //if (Flip) layoutRect.width = -layoutRect.width * 2;
                    layoutRect.height = 500;

                    GUI.DrawTexture(layoutRect, Character.texture, ScaleMode.ScaleToFit);
                    GUILayout.Space(500);
                }
            }

            EnterFromDirection = (ScenePositions)EditorGUILayout.EnumPopup("Enter From", EnterFromDirection);
            FinalPosition      = (ScenePositions)EditorGUILayout.EnumPopup("Final Position", FinalPosition);

            EnterTime = EditorGUILayout.Slider("Enter Time", EnterTime, 1f, 10f);
        }
        public void RemoveCharacter(string characterName, ScenePositions exitPosition, float exitTime)
        {
            Character character = CharactersOnScreen.Find(x => x.Name == characterName);

            Vector3 endPosition = new Vector3();

            switch (exitPosition)
            {
            case ScenePositions.Left:
                endPosition = new Vector3(-(character.Parent.rect.width + (character.Transform.rect.width / 2f)), 0, 0);
                break;

            case ScenePositions.Top:
                endPosition = new Vector3(0, character.Transform.rect.height, 0);
                break;

            case ScenePositions.Right:
                endPosition = new Vector3(character.Parent.rect.width + (character.Transform.rect.width / 2f), 0, 0);
                break;
            }

            CharactersOnScreen.Remove(character);
            character.MoveCharacter(endPosition, exitTime);
        }
        public void AddCharacter(string characterName, Sprite characterSprite, bool flip, ScenePositions enter, ScenePositions position, float enterTime)
        {
            MainCharacterStack.gameObject.SetActive(true);

            GameObject    obj = new GameObject(characterSprite.name, typeof(RectTransform));
            RectTransform parentTransform;

            Image spriteRenderer = obj.AddComponent <Image>();

            spriteRenderer.sprite         = characterSprite;
            spriteRenderer.preserveAspect = true;

            RectTransform spriteTransform = obj.GetComponent <RectTransform>();

            obj.transform.SetParent(MainCharacterStack);
            parentTransform           = MainCharacterStack;
            spriteTransform.sizeDelta = MainCharacterStack.sizeDelta;

            if (flip)
            {
                spriteTransform.localScale = new Vector3(-1, 1, 1);
            }
            else
            {
                spriteTransform.localScale = new Vector3(1, 1, 1);
            }

            Character character = obj.AddComponent <Character>();

            character.Name            = characterName;
            character.Transform       = spriteTransform;
            character.Parent          = parentTransform;
            character.CurrentPosition = position;
            character.SpriteRenderer  = spriteRenderer;

            float multiplier = characterSprite.rect.height / spriteTransform.rect.height;

            spriteTransform.sizeDelta = new Vector2(characterSprite.rect.width / multiplier, spriteTransform.sizeDelta.y);

            Vector2 startPosition = new Vector2();

            switch (enter)
            {
            case ScenePositions.Left:
                startPosition = new Vector2(-parentTransform.sizeDelta.x - spriteTransform.sizeDelta.x / 2, 0);
                break;

            case ScenePositions.Top:
                startPosition = new Vector2(0, parentTransform.sizeDelta.y + spriteTransform.sizeDelta.y / 2);
                break;

            case ScenePositions.Right:
                startPosition = new Vector2(parentTransform.sizeDelta.x + spriteTransform.sizeDelta.x / 2, 0);
                break;
            }

            spriteTransform.anchoredPosition = startPosition;
            CharactersOnScreen.Add(character);

            Vector2 endPosition = new Vector2();

            switch (position)
            {
            case ScenePositions.Left:
                endPosition = new Vector2(-(parentTransform.sizeDelta.x / 2), 0);

                Character[] leftCharacters = LeftSideCharacters.Reverse().ToArray();
                if (leftCharacters.Length > 1)
                {
                    float leftPosition = Mathf.Abs(parentTransform.sizeDelta.x);
                    float offset       = leftPosition / (leftCharacters.Length + 1);
                    for (int i = 0; i < leftCharacters.Length; i++)
                    {
                        Vector2 newPosition = new Vector2(-parentTransform.sizeDelta.x + offset * (i + 1), 0);
                        leftCharacters[i].MoveCharacter(newPosition, 1f);
                    }
                }
                else
                {
                    character.MoveCharacter(endPosition, enterTime);
                }
                break;

            case ScenePositions.Top:
                endPosition = new Vector2(0, 0);
                character.MoveCharacter(endPosition, enterTime);
                break;

            case ScenePositions.Middle:
                endPosition = new Vector2(0f, 0f);
                character.MoveCharacter(endPosition, enterTime);
                break;

            case ScenePositions.Right:
                endPosition = new Vector2(parentTransform.sizeDelta.x / 2, 0);

                Character[] rightCharacters = RightSideCharacters;
                if (rightCharacters.Length > 1)
                {
                    float rightPosition = Mathf.Abs(parentTransform.sizeDelta.x);
                    float offset        = rightPosition / (rightCharacters.Length + 1);
                    for (int i = 0; i < rightCharacters.Length; i++)
                    {
                        Vector2 newPosition = new Vector2(offset * (i + 1), 0);
                        rightCharacters[i].MoveCharacter(newPosition, 1f);
                    }
                }
                else
                {
                    character.MoveCharacter(endPosition, enterTime);
                }
                break;
            }
        }
Ejemplo n.º 4
0
 public override void DisplayLayout(Rect layoutRect, GUIStyle label)
 {
     CharacterName = EditorGUILayout.TextField("Character Name", CharacterName);
     ExitPosition  = (ScenePositions)EditorGUILayout.EnumPopup("Exit Position", ExitPosition);
     ExitTime      = EditorGUILayout.Slider("Exit Time", ExitTime, 1f, 10f);
 }