コード例 #1
0
    void Start()
    {
        initializePrimaryAgent();
        primaryAgent.actionDuration = this.actionDuration;
        readyToEmit = true;
        Debug.Log("Graphics Tier: " + Graphics.activeTier);
        this.agents.Add(primaryAgent);

        physicsSceneManager = GameObject.Find("PhysicsSceneManager").GetComponent <PhysicsSceneManager>();
    }
コード例 #2
0
    public void BreakObject(Collision collision)
    {
        // prefab swap will switch the entire object out with a new prefab object entirely
        if (breakType == BreakType.PrefabSwap)
        {
            // Disable this game object and spawn in the broken pieces
            Rigidbody rb = gameObject.GetComponent <Rigidbody>();

            // turn off everything except the top object
            foreach (Transform t in gameObject.transform)
            {
                t.gameObject.SetActive(false);
            }

            // spawn in correct prefab to swap to at object's last location and rotation
            // make sure to change to the correct variant of Prefab if the object isDirty

            // if gameObject.GetComponent<Dirty>() - first check to make sure if this object can become dirty
            // if object is dirty - probably get this from the "Dirty" component to keep everything nice and self contained
            // PrefabToSwapTo = DirtyPrefabToSwapTo
            if (gameObject.GetComponent <Dirty>())
            {
                // if the object is not clean, swap to the dirty prefab
                if (gameObject.GetComponent <Dirty>().IsDirty())
                {
                    PrefabToSwapTo = DirtyPrefabToSwapTo;
                }
            }

            GameObject resultObject = Instantiate(PrefabToSwapTo, transform.position, transform.rotation);
            broken = true;

            // ContactPoint cp = collision.GetContact(0);
            foreach (Rigidbody subRb in resultObject.GetComponentsInChildren <Rigidbody>())
            {
                subRb.velocity        = rb.velocity * 0.4f;
                subRb.angularVelocity = rb.angularVelocity * 0.4f;
            }

            rb.collisionDetectionMode = CollisionDetectionMode.Discrete;
            rb.isKinematic            = true;

            // if this object breaking is an egg, set rotation for the EggCracked object
            // quick if the result object is an egg hard set it's rotation because EGGS ARE WEIRD and are not the same form as their shelled version
            if (resultObject.GetComponent <SimObjPhysics>())
            {
                if (resultObject.GetComponent <SimObjPhysics>().Type == SimObjType.EggCracked)
                {
                    resultObject.transform.rotation = Quaternion.Euler(Vector3.zero);
                    PhysicsSceneManager psm = GameObject.Find("PhysicsSceneManager").GetComponent <PhysicsSceneManager>();
                    psm.Generate_InheritedObjectID(gameObject.GetComponent <SimObjPhysics>(), resultObject.GetComponent <SimObjPhysics>(), 0);

                    Rigidbody resultrb = resultObject.GetComponent <Rigidbody>();
                    resultrb.collisionDetectionMode = CollisionDetectionMode.ContinuousSpeculative;
                    resultrb.isKinematic            = false;
                }
            }

            // it's broken, make sure that it cant trigger this call again
            readytobreak = false;
        }

        // if decal type, do not switch out the object but instead swap materials to show cracked/broken parts
        if (breakType == BreakType.MaterialSwap)
        {
            // decal logic here
            if (MaterialSwapObjects.Length > 0)
            {
                for (int i = 0; i < MaterialSwapObjects.Length; i++)
                {
                    MaterialSwapObjects[i].MyObject.GetComponent <MeshRenderer>().materials = MaterialSwapObjects[i].OnMaterials;
                }
            }

            // if the object can be toggled on/off, if it is on, turn it off since it is now broken
            if (gameObject.GetComponent <CanToggleOnOff>())
            {
                gameObject.GetComponent <CanToggleOnOff>().isOn = false;
            }

            broken = true;
            // it's broken, make sure that it cant trigger this call again
            readytobreak = false;
        }

        if (breakType == BreakType.Decal)
        {
            // move shattered decal to location of the collision, or if there was no collision and this is being called
            // directly from the Break() action, create a default decal i guess?
            BreakForDecalType(collision);
        }

        BaseFPSAgentController primaryAgent = GameObject.Find("PhysicsSceneManager").GetComponent <AgentManager>().ReturnPrimaryAgent();

        if (primaryAgent.imageSynthesis)
        {
            if (primaryAgent.imageSynthesis.enabled)
            {
                primaryAgent.imageSynthesis.OnSceneChange();
            }
        }
    }
コード例 #3
0
ファイル: DroneBasket.cs プロジェクト: ekolve/ai2thor-lgtm
 // Use this for initialization
 void Start()
 {
     psManager = GameObject.Find("PhysicsSceneManager").GetComponent <PhysicsSceneManager>();
 }
コード例 #4
0
    //action to be called from PhysicsRemoteFPSAgentController
    public void Slice()
    {
        //if this is already sliced, we can't slice again so yeah stop that
        if (isSliced == true)
        {
            return;
        }

        //Disable this game object and spawn in the broken pieces
        Rigidbody rb = gameObject.GetComponent <Rigidbody>();

        rb.collisionDetectionMode = CollisionDetectionMode.Discrete;
        rb.isKinematic            = true;

        //turn off everything except the top object, so we can continue to report back isSliced meta info without the object being "active"
        foreach (Transform t in gameObject.transform)
        {
            t.gameObject.SetActive(false);
        }

        GameObject resultObject;

        if (!gameObject.GetComponent <SimObjPhysics>().DoesThisObjectHaveThisSecondaryProperty(SimObjSecondaryProperty.CanBeCooked))
        {
            //instantiate the normal object if this object is not cooked, otherwise....
            resultObject = Instantiate(ObjectToChangeTo, transform.position, transform.rotation);
            isSliced     = true;
        }

        //if the object can be cooked, check if it is cooked and then spawn the cooked object to change to, otherwise spawn the normal object
        else
        {
            //instantiate the normal object if this object is not cooked, otherwise....
            resultObject = Instantiate(ObjectToChangeTo, transform.position, transform.rotation);
            isSliced     = true;

            if (gameObject.GetComponent <CookObject>().IsCooked())
            {
                //cook all objects under the resultObject
                foreach (Transform t in resultObject.transform)
                {
                    t.GetComponent <CookObject>().Cook();
                }
            }
        }


        PhysicsSceneManager psm = GameObject.Find("PhysicsSceneManager").GetComponent <PhysicsSceneManager>();

        if (psm != null)
        {
            //if the spawned object is not a sim object itself, but if it's holding a ton of sim objects let's go
            if (!resultObject.transform.GetComponent <SimObjPhysics>())
            {
                //each instantiated sliced version of the object is a bunch of sim objects held by a master parent transform, so go into each one and assign the id to each based on the parent's id so
                //there is an association with the original source object
                int count = 0;
                foreach (Transform t in resultObject.transform)
                {
                    SimObjPhysics tsop = t.GetComponent <SimObjPhysics>();
                    psm.Generate_InheritedUniqueID(gameObject.GetComponent <SimObjPhysics>(), tsop, count);
                    count++;

                    //also turn on the kinematics of this object
                    Rigidbody trb = t.GetComponent <Rigidbody>();
                    trb.collisionDetectionMode = CollisionDetectionMode.ContinuousSpeculative;
                    trb.isKinematic            = false;
                }
            }

            else
            {
                //quick if the result object is an egg hard set it's rotation because EGGS ARE WEIRD and are not the same form as their shelled version
                if (resultObject.GetComponent <SimObjPhysics>().Type == SimObjType.EggCracked)
                {
                    resultObject.transform.rotation = Quaternion.Euler(Vector3.zero);
                }

                SimObjPhysics resultsop = resultObject.GetComponent <SimObjPhysics>();
                psm.Generate_InheritedUniqueID(gameObject.GetComponent <SimObjPhysics>(), resultsop, 0);

                Rigidbody resultrb = resultsop.GetComponent <Rigidbody>();
                resultrb.collisionDetectionMode = CollisionDetectionMode.ContinuousSpeculative;
                resultrb.isKinematic            = false;
            }
        }

        else
        {
            Debug.LogError("Physics Scene Manager object is missing from scene!");
        }
    }
コード例 #5
0
 // Start is called before the first frame update
 void Start()
 {
     agentManager = gameObject.GetComponent <AgentManager>();
     sceneManager = gameObject.GetComponent <PhysicsSceneManager>();
 }