コード例 #1
0
ファイル: Robot.cs プロジェクト: ebgolden/The-Robot-Games
    public Robot(string name, bool human, Head head, Body body, Mobility mobility, Attachment[] attachments)
    {
        Point position = new Point();

        cachedPosition      = position;
        cachedAngle         = position;
        force               = new Point();
        damageReceived      = 0;
        damageDealt         = 0;
        active              = true;
        positionInitialized = false;
        HUMAN               = human;
        if (name != default && name != "")
        {
            this.name = name;
        }
        else
        {
            this.name = DEFAULT_NAME;
        }
        HEAD        = head;
        BODY        = body;
        MOBILITY    = mobility;
        ATTACHMENTS = new Carousel <Attachment>();
        ATTACHMENTS.AddRange(attachments);
        if (HEAD == null || BODY == null || MOBILITY == null || !ATTACHMENTS.Exists(attachment => attachment.isWeapon()))
        {
            throw new Exception("Some parts of a robot are missing. Robots with missing parts will deleted.");
        }
        else
        {
            GAME_OBJECT = new GameObject();
            GAME_OBJECT.AddComponent <Rigidbody>();
            Vector3 robotFootprint = GAME_OBJECT.AddComponent <BoxCollider>().bounds.size;
            GAME_OBJECT.GetComponent <Collider>().isTrigger   = true;
            GAME_OBJECT.GetComponent <Rigidbody>().useGravity = true;
            setConstraints();
            Vector3 rescale = GAME_OBJECT.transform.localScale;
            rescale.x = (float)SCALE / robotFootprint.x;
            rescale.y = (float)SCALE / robotFootprint.z;
            rescale.z = (float)SCALE / robotFootprint.z;
            GAME_OBJECT.transform.localScale = rescale;
            HEAD.GAME_OBJECT.transform.SetParent(GAME_OBJECT.transform, false);
            BODY.GAME_OBJECT.transform.SetParent(GAME_OBJECT.transform, false);
            MOBILITY.GAME_OBJECT.transform.SetParent(GAME_OBJECT.transform, false);
            Vector3 robotPosition = GAME_OBJECT.transform.position = position.toVector3();
            MOBILITY.GAME_OBJECT.transform.position = new Vector3(robotPosition.x, 0, robotPosition.z);
            BODY.GAME_OBJECT.transform.position     = new Vector3(robotPosition.x, MOBILITY.GAME_OBJECT.GetComponent <Renderer>().bounds.size.y *POSITION_MULTIPLIER, robotPosition.z);
            if (HEAD.getShape() == Shape.SHAPES.HEMISPHERE)
            {
                HEAD.GAME_OBJECT.transform.position = new Vector3(robotPosition.x, MOBILITY.GAME_OBJECT.GetComponent <Renderer>().bounds.size.y *POSITION_MULTIPLIER + BODY.GAME_OBJECT.GetComponent <Renderer>().bounds.size.y - HEAD.GAME_OBJECT.GetComponent <Renderer>().bounds.size.y / 2, robotPosition.z);
            }
            else
            {
                HEAD.GAME_OBJECT.transform.position = new Vector3(robotPosition.x, MOBILITY.GAME_OBJECT.GetComponent <Renderer>().bounds.size.y *POSITION_MULTIPLIER + BODY.GAME_OBJECT.GetComponent <Renderer>().bounds.size.y, robotPosition.z);
            }
            double attachmentWeight = 0;
            if (ATTACHMENTS != null && ATTACHMENTS.Count > 0)
            {
                foreach (Attachment attachment in ATTACHMENTS)
                {
                    attachmentWeight += attachment.getWeight();
                }
            }
            WEIGHT          = HEAD.getWeight() + BODY.getWeight() + MOBILITY.getWeight() + attachmentWeight;
            MAX_ATTACHMENTS = BODY.getMaxAttachments();
            CLIMB_ANGLE     = MOBILITY.getClimbAngle();
            MAX_SPEED       = MOBILITY.getMaxSpeed();
            MAX_FORCE       = MOBILITY.getMaxForce();
            Vector3 footprint = GAME_OBJECT.AddComponent <BoxCollider>().bounds.size;
            SIZE = new Dimension(footprint.x, footprint.y, footprint.z);
        }
    }