public void InitPartOfBodyUI(PartOfBodyModel model, PartOfBodyController bodyController = null)
        {
            this.model = model;

            this.nodeControllers = new List <PartOfBodyNodeController>();

            // 初始化关节点
            for (int y = 0; y < model.height; y++)
            {
                for (int x = 0; x < model.weight; x++)
                {
                    PartOfBodyNodeController nodeController = Instantiate(this.PartOfBodyNodePrefab, this.transform).GetComponent <PartOfBodyNodeController>();

                    nodeController.model = model.GetPartOfBodyNodeModel(x, y);

                    nodeController.InitNodeUI();

                    this.nodeControllers.Add(nodeController);
                }
            }

            // 关节点连接
            if (model.type != PartOfBodyType.Body)
            {
                if (bodyController != null)
                {
                    this.transform.localPosition += this.CalculatePartOfBodyPosition(bodyController);
                }
                else
                {
                    Debug.LogError("InitPartOfBodyUI Error : bodyModel is null!");
                }
            }
        }
        private Vector3 CalculatePartOfBodyPosition(PartOfBodyController bodyController)
        {
            // 找到连接节点
            Vector2 bodyJoinPoint = bodyController.model.GetBodyJoinPoint(this.model.type);

            PartOfBodyNodeController bodyJoinNodeController = bodyController.GetNodeControllerWithJoin(bodyJoinPoint);
            PartOfBodyNodeController partJoinNodeController = this.GetNodeControllerWithJoin(this.model.joinPoint);

            // 判断连接方向
            PartOfBodyJoinDirection joinDirection = this.CalculateJoinDirection(this.model.joinPoint, bodyJoinPoint);

            // 得到部位节点世界坐标
            Vector3 joinNodeTargetLocalPosition = bodyJoinNodeController.transform.localPosition;

            switch (joinDirection)
            {
            case PartOfBodyJoinDirection.Left_Right:
                joinNodeTargetLocalPosition += Vector3.right * PartOfBodyNodeController.NodeSize;
                break;

            case PartOfBodyJoinDirection.Right_Left:
                joinNodeTargetLocalPosition += Vector3.left * PartOfBodyNodeController.NodeSize;
                break;

            case PartOfBodyJoinDirection.Up_Down:
                joinNodeTargetLocalPosition += Vector3.down * PartOfBodyNodeController.NodeSize;
                break;

            case PartOfBodyJoinDirection.Down_Up:
                joinNodeTargetLocalPosition += Vector3.up * PartOfBodyNodeController.NodeSize;
                break;

            default:
                break;
            }

            Vector3 joinNodeTargetWorldPosition = bodyController.transform.TransformPoint(joinNodeTargetLocalPosition);

            joinNodeTargetLocalPosition = this.transform.InverseTransformPoint(joinNodeTargetWorldPosition);
            // 得到部位坐标
            Vector3 offset = joinNodeTargetLocalPosition - partJoinNodeController.transform.localPosition;

            return(offset);
        }
Exemplo n.º 3
0
        private void GenerateSomePartOfBody(PartOfBodyType type, int w, int h, Vector2 joinPoint)
        {
            // 生成modle
            PartOfBodyModel bodyModel = new PartOfBodyModel();

            bodyModel.type  = type;
            bodyModel.grade = this.grade;
            bodyModel.level = this.level;

            bodyModel.weight = w;
            bodyModel.height = h;

            if (type == PartOfBodyType.Body)
            {
                bodyModel.SetBodyJoinPoint(PartOfBodyType.LetfArm, new Vector2(0, 0.8f));
                bodyModel.SetBodyJoinPoint(PartOfBodyType.RightArm, new Vector2(1f, 0.8f));
                bodyModel.SetBodyJoinPoint(PartOfBodyType.LeftLeg, new Vector2(0.2f, 0f));
                bodyModel.SetBodyJoinPoint(PartOfBodyType.RightLeg, new Vector2(0.8f, 0f));
                bodyModel.SetBodyJoinPoint(PartOfBodyType.Head, new Vector2(0.5f, 1f));
            }
            else
            {
                bodyModel.joinPoint = joinPoint;
            }

            bodyModel.maxHP = 100;
            bodyModel.curHP = 100;

            bodyModel.InitPartOfBodyNodeModels();

            PartOfBodyController bodyPartOfBodyController = Instantiate(this.PartOfBodyPrefab, this.PartOfBodyRoot.transform).GetComponent <PartOfBodyController>();

            this.partOfBodyControllers.Add(bodyPartOfBodyController);

            bodyPartOfBodyController.InitPartOfBodyUI(bodyModel, this.partOfBodyControllers[0]);
        }