Beispiel #1
0
        private ItemsBase LoadItem(ItemTypes itemType, string file)
        {
            if (AnyAnimsInFolder(file))
            {
                string name = Path.GetFileName(file);
                string path = file.Replace(_projectPath, string.Empty);
                path = path.Replace(name, string.Empty);
                if (string.IsNullOrWhiteSpace(path))
                {
                    path = "\\Root";
                }

                return(new CharacterDetails(name, path));
            }

            if (itemType == ItemTypes.Folder)
            {
                string name = Path.GetFileName(file);
                string path = file.Replace(_projectPath, string.Empty);
                path = path.Replace(name, string.Empty);
                if (string.IsNullOrWhiteSpace(path))
                {
                    path = "\\Root";
                }

                return(new FolderDetails(name, path));
            }

            if (itemType == ItemTypes.Animation)
            {
                return(AnimationDetails.Load(_projectPath, file));
            }

            return(null);
        }
Beispiel #2
0
        public void CreateAnimation(string name, string path)
        {
            AnimationDetails ad = new AnimationDetails(name, path);

            Items.Add(ad);
            ad.PostLoadFix();
            ad.Save(_projectPath);
        }
Beispiel #3
0
        private void OpenItem(TreeViewEventArgs e)
        {
            ItemsBase itemBase = e.Node.Tag as ItemsBase;

            _selectedItem = itemBase;
            if (itemBase.ItemType == ItemTypes.Animation)
            {
                if (itemBase is IEditable editable)
                {
                    _imageEditor.SetItem(editable);
                    AnimationDetails animationDetails = itemBase as AnimationDetails;
                    _propertyGrid.SelectedObject = animationDetails.AnimationOptions;
                }
            }
        }
Beispiel #4
0
    void RenderLowerBody()
    {
        if (!trLowerBody)
            trLowerBody = transform.Find(LOWER_CHILD_NAME);

        frames++;

        /*
        if (!punching)
        {
            // Left mouse click
            if (Input.GetMouseButtonUp(0))
            {
                punching = true;
                index = 0;
            }
        }

        if (punching)
        {
            currentAnimation = animationsArray.Find(p => p.animationState == AnimationStates.RiflePunch);
        }
        else
            currentAnimation = animationsArray.Find(p => p.animationState == AnimationStates.Idle);
         */

        Vector3 moveDirection = controller.velocity;// new Vector3(Input.GetAxis("Horizontal"), 0, 0);

        Vector3 currentDirection = Vector3.zero;

        // Set default Idle animation
        if (currentAnimation == null)
        {
            currentAnimation = animationsArray.Find(p => p.animationState == AnimationStates.Idle);
        }

        bool isMoving = moveDirection.magnitude > 0;

        if (lastAnimation == null)
        {
            if (moveDirection.magnitude == 0)
            {
                currentAnimation = animationsArray.Find(p => p.animationState == AnimationStates.Idle);
            }
        }
        else
        {
            switch (lastAnimation.animationState)
            {
                case AnimationStates.Idle:
                    if (isMoving)
                    {
                        if (moveDirection.x > 0)
                        {
                            if (Input.GetKey(KeyCode.LeftShift))
                            {
                                currentAnimation = animationsArray.Find(p => p.animationState == AnimationStates.StartRunning);
                                index = 0;
                                doUpperBodyTransitions = true;
                                runningTransitionTimer = 0;
                            }
                            else
                            {
                                currentAnimation = animationsArray.Find(p => p.animationState == AnimationStates.StartWalking);
                                index = 0;
                            }
                        }
                        else
                        {
                            currentAnimation = animationsArray.Find(p => p.animationState == AnimationStates.StartWalkingBackwards);
                            index = 0;
                        }
                    }
                    else
                    {
                        currentAnimation = lastAnimation;
                    }
                    break;
                case AnimationStates.StartWalking:
                    if (isMoving && moveDirection.x > 0)
                    {
                        if (index == lastAnimation.textures.Count - 1)
                        {
                            currentAnimation = animationsArray.Find(p => p.animationState == AnimationStates.Walking);
                        }
                    }
                    else
                    {
                        if (revertingIndex)
                        {
                            if (index == 0)
                            {
                                currentAnimation = animationsArray.Find(p => p.animationState == AnimationStates.Idle);
                                revertingIndex = false;
                            }
                        }
                        else
                        {
                            revertingIndex = true;

                            if (index == 0)
                                index = currentAnimation.textures.Count - 1;
                        }
                    }
                    break;
                case AnimationStates.Walking:
                    if (Input.GetKey(KeyCode.LeftShift))
                    {
                        bool canSwitch = false;
                        if (index < 2)
                        {
                            canSwitch = true;
                            index = 0;
                        }
                        else if (index > 20 && index < 23)
                        {
                            canSwitch = true;
                            index = 11;
                        }

                        if (canSwitch)
                        {
                            doUpperBodyTransitions = true;
                            runningTransitionTimer = 0;
                            currentAnimation = animationsArray.Find(p => p.animationState == AnimationStates.Running);
                        }
                        break;
                    }

                    if (isMoving && ((stopAtFlag && index <= stopAt) || !stopAtFlag) && moveDirection.x > 0)
                    {
                        currentDirection += moveDirection;
                    }
                    else
                    {
                        int newIndex = GetStopWalkingindex(index);
                        index = newIndex;
                        currentAnimation = animationsArray.Find(p => p.animationState == AnimationStates.StopWalking);
                        lastMovement = moveDirection;
                    }
                    break;
                case AnimationStates.StartWalkingBackwards:
                    if (isMoving && moveDirection.x < 0)
                    {
                        if (index == lastAnimation.textures.Count - 1)
                        {
                            currentAnimation = animationsArray.Find(p => p.animationState == AnimationStates.WalkingBackwards);
                            index = 5;
                        }
                    }
                    else
                    {
                        if (revertingIndex)
                        {
                            if (index == 0)
                            {
                                currentAnimation = animationsArray.Find(p => p.animationState == AnimationStates.Idle);
                                revertingIndex = false;
                            }
                        }
                        else
                        {
                            revertingIndex = true;

                            if (index == 0)
                                index = currentAnimation.textures.Count - 1;
                        }
                    }
                    break;
                case AnimationStates.StopWalking:
                    if (index >= currentAnimation.textures.Count - 1)
                    {
                        currentAnimation = animationsArray.Find(p => p.animationState == AnimationStates.Idle);
                        lastMovement = Vector3.zero;
                    }
                    else if (index < 38)
                    {
                        currentDirection += lastMovement;
                    }
                    break;
                case AnimationStates.WalkingBackwards:
                    if (isMoving && moveDirection.x < 0 && ((stopAtFlag && index <= stopAt) || !stopAtFlag))
                    {
                        currentDirection += moveDirection;
                        lastMovement = moveDirection;
                    }
                    else
                    {
                        if (index < 20)
                        {
                            currentAnimation = animationsArray.Find(p => p.animationState == AnimationStates.StopWalkingBack);
                        }

                        currentDirection += lastMovement;
                    }
                    break;
                case AnimationStates.StopWalkingBack:

                    if (index >= currentAnimation.textures.Count - 1)
                    {
                        currentAnimation = animationsArray.Find(p => p.animationState == AnimationStates.Idle);
                        lastMovement = Vector3.zero;
                    }
                    else if (index < 31)
                    {
                        currentDirection += lastMovement;
                    }
                    break;
                case AnimationStates.Running:
                    if (isMoving && ((stopAtFlag && index <= stopAt) || !stopAtFlag) && moveDirection.x > 0)
                    {
                        if (Input.GetKey(KeyCode.LeftShift))
                        {
                            currentDirection += moveDirection * shiftForward;
                        }
                        else
                        {
                            currentDirection += moveDirection * shiftForward;
                            lastMovement = currentDirection;

                            if (index < 10)
                            {
                                currentAnimation = animationsArray.Find(p => p.animationState == AnimationStates.StopRunning);
                                doUpperBodyTransitions = true;
                                runningTransitionTimer = 0;
                            }
                        }
                    }
                    else
                    {
                        if (index < 10)
                        {
                            currentAnimation = animationsArray.Find(p => p.animationState == AnimationStates.StopRunning);
                            doUpperBodyTransitions = true;
                            runningTransitionTimer = 0;
                        }

                        currentDirection += moveDirection * shiftForward;
                        lastMovement = currentDirection;
                    }
                    break;
                case AnimationStates.StopRunning:
                    if (index >= currentAnimation.textures.Count - 1)
                    {
                        currentAnimation = animationsArray.Find(p => p.animationState == AnimationStates.Idle);
                        lastMovement = Vector3.zero;

                        runningTransitionTimer = 0;
                        doUpperBodyTransitions = true;
                    }
                    else
                    {
                        if (index == 24)
                        {
                            runningTransitionTimer = 0;
                            doUpperBodyTransitions = true;
                        }

                        if (index < 25)
                        {
                            currentDirection += lastMovement;
                        }
                        else if (index > 28)
                        {
                            if (isMoving && ((stopAtFlag && index <= stopAt) || !stopAtFlag) && moveDirection.x > 0)
                            {
                                index = 15;
                                currentAnimation = animationsArray.Find(p => p.animationState == AnimationStates.Walking);
                                lastMovement = Vector3.zero;

                                runningTransitionTimer = 0;
                                doUpperBodyTransitions = true;
                            }
                        }
                    }
                    break;
                case AnimationStates.StartRunning:
                    if (isMoving && moveDirection.x > 0)
                    {
                        if (index == lastAnimation.textures.Count - 1)
                        {
                            currentAnimation = animationsArray.Find(p => p.animationState == AnimationStates.Running);
                            index = 8;
                        }
                    }
                    else
                    {
                        if (revertingIndex)
                        {
                            if (index == 0)
                            {
                                currentAnimation = animationsArray.Find(p => p.animationState == AnimationStates.Idle);
                                revertingIndex = false;
                            }
                        }
                        else
                        {
                            revertingIndex = true;

                            doUpperBodyTransitions = true;
                            runningTransitionTimer = 0;

                            if (index == 0)
                                index = currentAnimation.textures.Count - 1;
                        }
                    }
                    break;
            }
        }

        if (currentAnimation == null && lastAnimation != null)
            currentAnimation = lastAnimation;

        if (index > currentAnimation.textures.Count - 1)
            index = -1;

        if ((currentAnimation.animationState == AnimationStates.Running && frames > runningFrames) || (currentAnimation.animationState != AnimationStates.Running && frames > 0))
        {
            if (revertingIndex)
            {
                index--;
            }
            else
                index += 1;

            frames = 0;
        }

        if (index < 0)
            index = 0;

        /*
        Ray punchRay = new Ray(transform.position, transform.TransformDirection(Vector3.right));

        Debug.DrawRay(punchRay.origin, punchRay.direction * punchDistance, Color.red);

        index += 1;

        index = Mathf.Clamp(index, 0, currentAnimation.textures.Count - 1);

        if (punching)
        {
            if (index == currentAnimation.textures.Count - 1)
            {
                punching = false;
            }
            else if (index == 5)
            {
                // Here is a real punch: See the animation 'rifle-punch/5.png'

                // Today can punch only right
                RaycastHit hit;

                if (Physics.Raycast(punchRay, out hit, punchDistance))
                {
                    Debug.Log("Got punch hit: " + hit.transform.name, hit.transform);
                    hit.rigidbody.AddForce(punchRay.direction, ForceMode.Impulse);
                }
                else
                    Debug.Log("Not punch hit :(");
            }
        }
         */
        if (index >= 0 && currentAnimation.textures.Count > 0 && currentAnimation.textures.Count - 1 >= index)
            trLowerBody.renderer.material.mainTexture = currentAnimation.textures[index];

        lastAnimation = currentAnimation;

        //Debug.Log(currentAnimation.animationState + " " + "isMoving = " + isMoving + " " + index);

        //CollisionFlags flags = controller.Move(currentDirection * Time.deltaTime);
        //grounded = (flags & CollisionFlags.CollidedBelow) != 0;
        // Lock z movement
        //controller.transform.position = new Vector3(controller.transform.position.x, controller.transform.position.y, -10);
    }
        public void ShouldFullPath(string name, string path, string expectedFullPath)
        {
            AnimationDetails ad = new AnimationDetails(name, path);

            ad.FullPath.Should().Be(expectedFullPath);
        }
Beispiel #6
0
 public void Add(AnimationDetails animationDetails)
 {
     animations.Add(animationDetails);
 }
 internal void SetParent(AnimationDetails animationDetails)
 {
     _animationDetails = animationDetails;
 }