Exemplo n.º 1
0
        public Dictionary <string, object> GetPos(CpuBlock cpu)
        {
            Vector3 myPos = Rigidbody.position;

            return(new Dictionary <string, object> {
                { "absolutePos", BlockUtils.Vec2Obj(cpu, myPos) }
            });
        }
        public Dictionary <string, object> GetV(CpuBlock cpu)
        {
            Vector3 myV = Rigidbody.velocity;

            return(new Dictionary <string, object> {
                { "velocity", BlockUtils.Vec2Obj(cpu, myV) }
            });
        }
Exemplo n.º 3
0
        public Dictionary <string, object> GetAng(CpuBlock cpu)
        {
            Quaternion quaternion = base.transform.rotation;
            Vector3    angV       = Rigidbody.angularVelocity;

            return(new Dictionary <string, object>
            {
                { "quaternion", BlockUtils.Quat2Obj(cpu, quaternion) },
                { "velocity", BlockUtils.Vec2Obj(cpu, angV) }
            });
        }
Exemplo n.º 4
0
        public Dictionary <string, object> GetTargetObject(CpuBlock cpu)
        {
            if (closestCollider == null)
            {
                return(null);
            }

            if (detectedObjectInfo != null)
            {
                return(detectedObjectInfo);
            }

            // Static objects have rigidBody.isKinematic
            var rigidBody = closestCollider.attachedRigidbody;
            // Mesh has no rigidbody
            var isStaic   = (rigidBody == null || rigidBody.isKinematic);
            var transform = closestCollider.transform;
            // AI has EntityAI
            var parentAI = transform.GetComponentInParent <EntityAI>();
            var simpleAI = transform.GetComponentInParent <EnemyAISimple>();
            // Blocks have BlockBehavior
            var parentBlock = transform.GetComponentInParent <BlockBehaviour>();
            var objectInfo  = rigidBody?.GetComponentInParent <SimBehaviour>();
            var bombInfo    = rigidBody?.GetComponentInParent <ExplodeOnCollide>();
            var killable    = rigidBody?.GetComponentInParent <InjuryController>();
            var projectile  = rigidBody?.GetComponentInParent <ProjectileScript>();
            var isDead      = parentAI != null && parentAI.isDead || simpleAI != null && simpleAI.isDead;
            var canBreak    = objectInfo is IExplosionEffect ||
                              rigidBody?.GetComponent <PhysNodeTile>() != null ||
                              rigidBody?.GetComponent <StructuralPhysTile>() != null;
            var objectType = (bombInfo != null || (parentBlock is ExplodeOnCollideBlock) ? "bomb"
                                : parentBlock != null ? "block"
                                : projectile != null ? "projectile"
                                : isDead ? "dead"
                                : parentAI != null || simpleAI != null ? "unit"
                                : killable != null ? "creature"
                                : canBreak ? "breakable"
                                : objectInfo != null ? "entity"
                                : "other");
            Vector3 relativePos = closestPoint - sensorPos.position;
            Vector3 targetV     = rigidBody ? rigidBody.velocity : Vector3.zero;

            detectedObjectInfo = new Dictionary <string, object>
            {
                { "static", isStaic ? (long)1 : 0 },
                { "type", objectType },
                { "relativePos", BlockUtils.Vec2Obj(cpu, relativePos) },
                { "absolutePos", BlockUtils.Vec2Obj(cpu, closestPoint) },
                { "velocity", BlockUtils.Vec2Obj(cpu, targetV) }
            };

            return(detectedObjectInfo);
        }
Exemplo n.º 5
0
        public static JsValue Vec2Obj(CpuBlock b, Vector3 v)
        {
            var vec3 = b.Interp.Global.Get(CpuVector3.Name) as IConstructor;

            return(vec3.Construct(new JsValue[] { v.x, v.y, v.z }, null));
        }
Exemplo n.º 6
0
        public static ObjectInstance Quat2Obj(CpuBlock b, Quaternion q)
        {
            var quat = b.Interp.Global.Get(CpuQuaternion.Name) as IConstructor;

            return(quat.Construct(new JsValue[] { q.x, q.y, q.z, q.w }, null));
        }