Exemplo n.º 1
0
    public override bool OnSceneView()
    {
        bool flag = base.OnSceneView();

        AuthorChHit.Rep rep  = this.self.primary;
        AuthorChHit.Rep rep1 = this.self.secondary;
        AuthorChHit.Rep rep2 = new AuthorChHit.Rep();
        AuthorChHit.Rep rep3 = new AuthorChHit.Rep();
        if (this.connect)
        {
            rep2 = this.connect.primary;
            rep3 = this.connect.secondary;
            if (!rep3.valid)
            {
                rep3 = rep2;
            }
        }
        if (rep.valid)
        {
            flag = flag | this.DoTransformHandles(ref rep, ref rep2);
        }
        if (rep1.valid)
        {
            flag = flag | this.DoTransformHandles(ref rep1, ref rep3);
        }
        return(flag);
    }
Exemplo n.º 2
0
    public override bool OnSceneView()
    {
        bool flag = base.OnSceneView();

        AuthorChHit.Rep primary   = this.self.primary;
        AuthorChHit.Rep secondary = this.self.secondary;
        AuthorChHit.Rep connect   = new AuthorChHit.Rep();
        AuthorChHit.Rep rep4      = new AuthorChHit.Rep();
        if (this.connect != null)
        {
            connect = this.connect.primary;
            rep4    = this.connect.secondary;
            if (!rep4.valid)
            {
                rep4 = connect;
            }
        }
        if (primary.valid)
        {
            flag |= this.DoTransformHandles(ref primary, ref connect);
        }
        if (secondary.valid)
        {
            flag |= this.DoTransformHandles(ref secondary, ref rep4);
        }
        return(flag);
    }
Exemplo n.º 3
0
 private void CreatedCollider(Collider created, AuthorChHit.Rep repFormat, bool addJoints, int?layerIndex)
 {
     if (!created)
     {
         return;
     }
     repFormat.bone = created.transform;
     if (addJoints)
     {
         Rigidbody rigidbody = created.rigidbody;
         if (!rigidbody)
         {
             rigidbody = created.gameObject.AddComponent <Rigidbody>();
         }
         rigidbody.mass        = this.mass;
         rigidbody.drag        = this.drag;
         rigidbody.angularDrag = this.angularDrag;
         if (this.myJoints != null)
         {
             AuthorChJoint[] authorChJointArray = this.myJoints;
             for (int i = 0; i < (int)authorChJointArray.Length; i++)
             {
                 AuthorChJoint authorChJoint = authorChJointArray[i];
                 if (authorChJoint)
                 {
                     authorChJoint.AddJoint(repFormat.bone.root, ref repFormat);
                 }
             }
         }
     }
     if (layerIndex.HasValue)
     {
         created.gameObject.layer = layerIndex.Value;
     }
 }
Exemplo n.º 4
0
    public Joint AddJoint(Transform root, ref AuthorChHit.Rep self)
    {
        Joint joint;

        switch (this.kind)
        {
        case AuthorChJoint.Kind.Hinge:
        {
            HingeJoint hingeJoint = this.CreateJoint <HingeJoint>(root, ref self);
            hingeJoint.limits    = this.limit;
            hingeJoint.useLimits = this.useLimit;
            hingeJoint.motor     = this.motor;
            hingeJoint.useMotor  = this.useMotor;
            hingeJoint.spring    = this.spring;
            hingeJoint.useSpring = this.useSpring;
            joint = hingeJoint;
            break;
        }

        case AuthorChJoint.Kind.Character:
        {
            CharacterJoint characterJoint = this.CreateJoint <CharacterJoint>(root, ref self);
            characterJoint.swingAxis      = self.AxisFlip(this.swingAxis);
            characterJoint.lowTwistLimit  = this.lowTwist;
            characterJoint.highTwistLimit = this.highTwist;
            characterJoint.lowTwistLimit  = this.lowTwist;
            characterJoint.swing1Limit    = this.swing1;
            characterJoint.swing2Limit    = this.swing2;
            joint = characterJoint;
            break;
        }

        case AuthorChJoint.Kind.Fixed:
        {
            joint = this.CreateJoint <FixedJoint>(root, ref self);
            break;
        }

        case AuthorChJoint.Kind.Spring:
        {
            SpringJoint springSpring = this.CreateJoint <SpringJoint>(root, ref self);
            springSpring.spring      = this.spring_spring;
            springSpring.damper      = this.spring_damper;
            springSpring.minDistance = this.spring_min;
            springSpring.maxDistance = this.spring_max;
            joint = springSpring;
            break;
        }

        default:
        {
            return(null);
        }
        }
        return(joint);
    }
Exemplo n.º 5
0
    public Joint AddJoint(Transform root, ref AuthorChHit.Rep self)
    {
        switch (this.kind)
        {
        case Kind.Hinge:
        {
            HingeJoint joint4 = this.CreateJoint <HingeJoint>(root, ref self);
            joint4.limits    = this.limit;
            joint4.useLimits = this.useLimit;
            joint4.motor     = this.motor;
            joint4.useMotor  = this.useMotor;
            joint4.spring    = this.spring;
            joint4.useSpring = this.useSpring;
            return(joint4);
        }

        case Kind.Character:
        {
            CharacterJoint joint2 = this.CreateJoint <CharacterJoint>(root, ref self);
            joint2.swingAxis      = self.AxisFlip(this.swingAxis);
            joint2.lowTwistLimit  = this.lowTwist;
            joint2.highTwistLimit = this.highTwist;
            joint2.lowTwistLimit  = this.lowTwist;
            joint2.swing1Limit    = this.swing1;
            joint2.swing2Limit    = this.swing2;
            return(joint2);
        }

        case Kind.Fixed:
            return(this.CreateJoint <FixedJoint>(root, ref self));

        case Kind.Spring:
        {
            SpringJoint joint5 = this.CreateJoint <SpringJoint>(root, ref self);
            joint5.spring      = this.spring_spring;
            joint5.damper      = this.spring_damper;
            joint5.minDistance = this.spring_min;
            joint5.maxDistance = this.spring_max;
            return(joint5);
        }
        }
        return(null);
    }
Exemplo n.º 6
0
 private void ConfigureJointShared(Joint joint, Transform root, ref AuthorChHit.Rep self)
 {
     AuthorChHit.Rep rep;
     if (this.connect)
     {
         if (!self.mirrored)
         {
             rep = this.connect.primary;
             if (!rep.valid)
             {
                 rep = this.connect.secondary;
             }
         }
         else
         {
             rep = this.connect.secondary;
             if (!rep.valid)
             {
                 rep = this.connect.primary;
             }
         }
         if (!rep.valid)
         {
             Debug.LogWarning("No means of making/getting rigidbody", this.connect);
         }
         else
         {
             Transform transforms = root.FindChild(rep.path);
             Rigidbody rigidbody  = transforms.rigidbody;
             if (!rigidbody)
             {
                 rigidbody = transforms.gameObject.AddComponent <Rigidbody>();
             }
             joint.connectedBody = rigidbody;
         }
     }
     joint.anchor      = self.Flip(this.anchor);
     joint.axis        = self.AxisFlip(this.axis);
     joint.breakForce  = this.breakForce;
     joint.breakTorque = this.breakTorque;
 }
Exemplo n.º 7
0
    private bool DoTransformHandles(ref AuthorChHit.Rep self, ref AuthorChHit.Rep connect)
    {
        if (!self.valid)
        {
            return(false);
        }
        Vector3   vector3   = self.Flip(this.anchor);
        Vector3   vector31  = self.AxisFlip(this.axis);
        Vector3   vector32  = self.AxisFlip(this.swingAxis);
        Matrix4x4 matrix4x4 = AuthorShared.Scene.matrix;

        if (connect.valid)
        {
            AuthorShared.Scene.matrix = connect.bone.localToWorldMatrix;
            Color color = AuthorShared.Scene.color;
            AuthorShared.Scene.color = color * new Color(1f, 1f, 1f, 0.4f);
            Vector3 vector33 = connect.bone.InverseTransformPoint(self.bone.position);
            if (vector33 != Vector3.zero)
            {
                AuthorShared.Scene.DrawBone(Vector3.zero, Quaternion.LookRotation(vector33), vector33.magnitude, 0.02f, new Vector3(0.05f, 0.05f, 0.5f));
            }
            AuthorShared.Scene.color = color;
        }
        AuthorShared.Scene.matrix = self.bone.localToWorldMatrix;
        bool flag = false;

        if (AuthorShared.Scene.PivotDrag(ref vector3, ref vector31))
        {
            flag        = true;
            this.anchor = self.Flip(vector3);
            this.axis   = self.AxisFlip(vector31);
        }
        AuthorChJoint.Kind kind = this.kind;
        if (kind != AuthorChJoint.Kind.Hinge)
        {
            if (kind == AuthorChJoint.Kind.Character)
            {
                Color color1 = AuthorShared.Scene.color;
                AuthorShared.Scene.color = color1 * AuthorChJoint.twistColor;
                SoftJointLimit softJointLimit  = this.lowTwist;
                SoftJointLimit softJointLimit1 = this.highTwist;
                if (AuthorShared.Scene.LimitDrag(vector3, vector31, ref this.twistOffset, ref softJointLimit, ref softJointLimit1))
                {
                    flag           = true;
                    this.lowTwist  = softJointLimit;
                    this.highTwist = softJointLimit1;
                }
                AuthorShared.Scene.color = color1 * AuthorChJoint.swing1Color;
                softJointLimit           = this.swing1;
                if (AuthorShared.Scene.LimitDrag(vector3, vector32, ref this.swingOffset1, ref softJointLimit))
                {
                    flag        = true;
                    this.swing1 = softJointLimit;
                }
                AuthorShared.Scene.color = color1 * AuthorChJoint.swing2Color;
                softJointLimit           = this.swing2;
                if (AuthorShared.Scene.LimitDrag(vector3, Vector3.Cross(vector32, vector31), ref this.swingOffset2, ref softJointLimit))
                {
                    flag        = true;
                    this.swing2 = softJointLimit;
                }
                AuthorShared.Scene.color = color1;
            }
        }
        else if (this.useLimit)
        {
            JointLimits jointLimit = this.limit;
            if (AuthorShared.Scene.LimitDrag(vector3, vector31, ref this.limitOffset, ref jointLimit))
            {
                flag       = true;
                this.limit = jointLimit;
            }
        }
        AuthorShared.Scene.matrix = matrix4x4;
        return(flag);
    }
Exemplo n.º 8
0
 private TJoint CreateJoint <TJoint>(Transform root, ref AuthorChHit.Rep self)
     where TJoint : Joint
 {
     return(this.ConfigJoint <TJoint>(self.bone.gameObject.AddComponent <TJoint>(), root, ref self));
 }
Exemplo n.º 9
0
 private TJoint ConfigJoint <TJoint>(TJoint joint, Transform root, ref AuthorChHit.Rep self)
     where TJoint : Joint
 {
     this.ConfigureJointShared(joint, root, ref self);
     return(joint);
 }
Exemplo n.º 10
0
    private bool DoTransformHandles(ref AuthorChHit.Rep self, ref AuthorChHit.Rep connect)
    {
        if (!self.valid)
        {
            return(false);
        }
        Vector3   anchor  = self.Flip(this.anchor);
        Vector3   axis    = self.AxisFlip(this.axis);
        Vector3   vector3 = self.AxisFlip(this.swingAxis);
        Matrix4x4 matrix  = AuthorShared.Scene.matrix;

        if (connect.valid)
        {
            AuthorShared.Scene.matrix = connect.bone.localToWorldMatrix;
            Color color = AuthorShared.Scene.color;
            AuthorShared.Scene.color = color * new Color(1f, 1f, 1f, 0.4f);
            Vector3 forward = connect.bone.InverseTransformPoint(self.bone.position);
            if (forward != Vector3.zero)
            {
                Quaternion rot = Quaternion.LookRotation(forward);
                AuthorShared.Scene.DrawBone(Vector3.zero, rot, forward.magnitude, 0.02f, new Vector3(0.05f, 0.05f, 0.5f));
            }
            AuthorShared.Scene.color = color;
        }
        AuthorShared.Scene.matrix = self.bone.localToWorldMatrix;
        bool flag = false;

        if (AuthorShared.Scene.PivotDrag(ref anchor, ref axis))
        {
            flag        = true;
            this.anchor = self.Flip(anchor);
            this.axis   = self.AxisFlip(axis);
        }
        switch (this.kind)
        {
        case Kind.Hinge:
            if (this.useLimit)
            {
                JointLimits limits = this.limit;
                if (AuthorShared.Scene.LimitDrag(anchor, axis, ref this.limitOffset, ref limits))
                {
                    flag       = true;
                    this.limit = limits;
                }
            }
            break;

        case Kind.Character:
        {
            Color color2 = AuthorShared.Scene.color;
            AuthorShared.Scene.color = color2 * twistColor;
            SoftJointLimit lowTwist  = this.lowTwist;
            SoftJointLimit highTwist = this.highTwist;
            if (AuthorShared.Scene.LimitDrag(anchor, axis, ref this.twistOffset, ref lowTwist, ref highTwist))
            {
                flag           = true;
                this.lowTwist  = lowTwist;
                this.highTwist = highTwist;
            }
            AuthorShared.Scene.color = color2 * swing1Color;
            lowTwist = this.swing1;
            if (AuthorShared.Scene.LimitDrag(anchor, vector3, ref this.swingOffset1, ref lowTwist))
            {
                flag        = true;
                this.swing1 = lowTwist;
            }
            AuthorShared.Scene.color = color2 * swing2Color;
            lowTwist = this.swing2;
            if (AuthorShared.Scene.LimitDrag(anchor, Vector3.Cross(vector3, axis), ref this.swingOffset2, ref lowTwist))
            {
                flag        = true;
                this.swing2 = lowTwist;
            }
            AuthorShared.Scene.color = color2;
            break;
        }
        }
        AuthorShared.Scene.matrix = matrix;
        return(flag);
    }