Ejemplo n.º 1
0
        public InterfaceListenerEvent(InterfaceGen iface, Method method, string name, string nameSpec, string fullDelegateName, string wrefSuffix, string add, string remove, bool hasHandlerArgument, CodeGenerationOptions opt)
        {
            Name      = name;
            EventType = new TypeReferenceWriter(opt.GetOutputName(fullDelegateName));

            IsPublic = true;

            SourceWriterExtensions.AddSupportedOSPlatform(Attributes, method, opt);

            HasAdd = true;

            AddBody.Add($"global::Java.Interop.EventHelper.AddEventHandler<{opt.GetOutputName (iface.FullName)}, {opt.GetOutputName (iface.FullName)}Implementor>(");
            AddBody.Add($"ref weak_implementor_{wrefSuffix},");
            AddBody.Add($"__Create{iface.Name}Implementor,");
            AddBody.Add($"{add + (hasHandlerArgument ? "_Event_With_Handler_Helper" : null)},");
            AddBody.Add($"__h => __h.{nameSpec}Handler += value);");

            HasRemove = true;

            RemoveBody.Add($"global::Java.Interop.EventHelper.RemoveEventHandler<{opt.GetOutputName (iface.FullName)}, {opt.GetOutputName (iface.FullName)}Implementor>(");
            RemoveBody.Add($"ref weak_implementor_{wrefSuffix},");
            RemoveBody.Add($"{opt.GetOutputName (iface.FullName)}Implementor.__IsEmpty,");
            RemoveBody.Add($"{remove},");
            RemoveBody.Add($"__h => __h.{nameSpec}Handler -= value);");

            if (hasHandlerArgument)
            {
                helper_method = new InterfaceListenerEventHandlerHelper(iface, method, add, opt);
            }
        }
Ejemplo n.º 2
0
    void OnEnable()
    {
        myTransform         = transform;
        RemoveBodyComponent = GetComponent <RemoveBody>();
        Mathf.Clamp01(sloMoDeathChance);
        if (removeBody && RemoveBodyComponent)        //remove body timer starts if RwmoveBody.cs script is enabled
        {
            RemoveBodyComponent.enabled = false;
        }
        if (!AIComponent)
        {
            AIComponent = myTransform.GetComponent <AI>();
        }
        initialHitPoints = hitPoints;
        bodies           = GetComponentsInChildren <Rigidbody>();

        //GameObject Data;
        killEnemiesRef = GameObject.FindGameObjectWithTag("DataBase").GetComponent <KillAllEnemiesMission> ();

        if (AIComponent.factionNum == 3)         // check if enemy is from enemies faction
        {
            killEnemiesRef.EnemyCounter += 1;
        }

        if (gameObject.GetComponent <AudioSource> ())
        {
            audioS = gameObject.GetComponent <AudioSource> ();
        }

        datacomps = GameObject.FindGameObjectWithTag("DataBase").GetComponent <DataComps> ();
    }
Ejemplo n.º 3
0
 void OnEnable()
 {
     myTransform         = transform;
     RemoveBodyComponent = GetComponent <RemoveBody>();
     Mathf.Clamp01(sloMoDeathChance);
     if (removeBody && RemoveBodyComponent)        //remove body timer starts if RwmoveBody.cs script is enabled
     {
         RemoveBodyComponent.enabled = false;
     }
     if (!AIComponent)
     {
         AIComponent = myTransform.GetComponent <AI>();
     }
     initialHitPoints = hitPoints;
     bodies           = GetComponentsInChildren <Rigidbody>();
 }
Ejemplo n.º 4
0
    //this method called if the NPC dies and only has one capsule collider for collision
    //which will be instantiated in place of the main NPC object (which is removed from the scene)
    void Die()
    {
        RaycastHit rayHit;

        // Play a dying audio clip
        if (dieSound)
        {
            PlayAudioAtPos.PlayClipAt(dieSound, transform.position, 1.0f);
        }

        AIComponent.NPCRegistryComponent.UnregisterNPC(AIComponent);        //unregister NPC from main NPC registry
        if (AIComponent.spawned && AIComponent.NPCSpawnerComponent)
        {
            AIComponent.NPCSpawnerComponent.UnregisterSpawnedNPC(AIComponent);            //unregister NPC from spawner registry
        }

        AIComponent.agent.Stop();
        AIComponent.StopAllCoroutines();

        // Replace NPC object with the dead body
        if (deadReplacement)
        {
            //drop arrows if corpse disappears
            ArrowObject[] arrows = gameObject.GetComponentsInChildren <ArrowObject>(true);
            foreach (ArrowObject arr in arrows)
            {
                arr.transform.parent        = null;
                arr.myRigidbody.isKinematic = false;
                arr.myBoxCol.isTrigger      = false;
                arr.gameObject.tag          = "Usable";
                arr.falling = true;
            }

            dead = Instantiate(deadReplacement, transform.position, transform.rotation) as Transform;
            RemoveBodyComponent = dead.GetComponent <RemoveBody>();

            // Copy position & rotation from the old hierarchy into the dead replacement
            CopyTransformsRecurse(transform, dead);

            Collider[] colliders = dead.GetComponentsInChildren <Collider>();
            foreach (Collider col in colliders)
            {
                Physics.IgnoreCollision(col, AIComponent.FPSWalker.capsule, true);
            }

            //apply damage force to NPC ragdoll
            if (Physics.SphereCast(attackerPos2, 0.2f, attackDir2, out rayHit, 750.0f, raymask) &&
                rayHit.rigidbody &&
                attackDir2.x != 0)
            {
                //apply damage force to the ragdoll rigidbody hit by the sphere cast (can be any body part)
                rayHit.rigidbody.AddForce(attackDir2 * 10.0f, ForceMode.Impulse);
            }
            else              //apply damage force to NPC ragdoll if being damaged by an explosive object or other damage source without a specified attack direction

            {
                Component[] bodies;
                bodies = dead.GetComponentsInChildren <Rigidbody>();
                foreach (Rigidbody body in bodies)
                {
                    if (explosionCheck)
                    {
                        //if(body.transform.name == "Chest"){//only apply damage force to the chest of the ragdoll if damage is from non-player source
                        //calculate direction to apply damage force to ragdoll
                        body.AddForce((myTransform.position - (attackerPos2 + (Vector3.up * -2.5f))).normalized * Random.Range(4.5f, 7.5f), ForceMode.Impulse);
                        //}
                    }
                    else
                    {
                        if (body.transform.name == "Chest")                        //only apply damage force to the chest of the ragdoll if damage is from non-player source
                        //calculate direction to apply damage force to ragdoll
                        {
                            body.AddForce((myTransform.position - attackerPos2).normalized * 10.0f, ForceMode.Impulse);
                        }
                    }
                }
            }

            //initialize the RemoveBody.cs script attached to the NPC ragdoll
            if (RemoveBodyComponent)
            {
                if (removeBody)
                {
                    RemoveBodyComponent.enabled      = true;
                    RemoveBodyComponent.bodyStayTime = bodyStayTime;                    //pass bodyStayTime to RemoveBody.cs script
                }
                else
                {
                    RemoveBodyComponent.enabled = false;
                }
            }

            //Determine if this object or parent should be removed.
            //This is to allow for different hit detection collider types as children of NPC parent.
            if (notParent)
            {
                Destroy(transform.parent.gameObject);
            }
            else
            {
                if (AIComponent.factionNum == 3)
                {
                    killEnemiesRef.EnemyCounter -= 1;
                }
                Destroy(transform.gameObject);
            }
        }
    }
Ejemplo n.º 5
0
    public void Dead()
    {
        // if (SceneManagement.Name.Contains("Sniper"))
        // {
        //     Debug.LogFormat("Remove Arrow offscreen indicator for: {0}", this.gameObject.name);
        //    // OffScreenScript.RemoveIndicator(this.gameObject.transform);
        // }

        //UnityEditor.EditorApplication.isPaused = true;

        // Play a dying audio clip
        if (audio.deadClip)
        {
            AudioSource.PlayClipAtPoint(audio.deadClip, position);
        }
        // E x i t
        if (manager && manager.CubeManager)
        {
            // Spawn pickable blocks
            manager.CubeManager.SpawnBlocks(position + Vector3.up * 1, renderer.material);
        }
        // E x i t: if we don't have  dommy prefab
        if (ragdollPrefab)
        {
            // Get the remove body component
            RemoveBody body = ragdollPrefab.GetComponent <RemoveBody>();

            // Can we spawn the gun
            if (body && body.GunPickup)
            {
                GameObject pickup = Instantiate(body.GunPickup, position + Vector3.up * 1.5f, body.GunPickup.transform.rotation) as GameObject;

                // For balancing the amount of ammo in each group (b)
                if (BalanceCentral.instance != null)
                {
                    AmmoPickupC17 ammoPickup = pickup.GetComponent <AmmoPickupC17>();
                    if (ammoPickup != null)
                    {
                        //ammoPickup.ammoToAdd += (int)(BalanceCentral.instance.AmmoDrops * (ammoPickup.ammoToAdd / 100.0f));
                        ammoPickup.ammoToAdd += (int)(BalanceCentral.instance.GetAmmoDrops() * (ammoPickup.ammoToAdd / 100.0f));
                        //Debug.Log ("Ammo Drops " + BalanceCentral.instance.GetAmmoDrops ());
                    }
                }
            }

            // Make sure the skin on our dead body is the same as the one on our living body
            //SkinnedMeshRenderer skinRenderer = body.GetComponentInChildren<SkinnedMeshRenderer>();
            //if (skinRenderer != null)
            //{
            //	skinRenderer.material.mainTexture = _dependencies.renderer.material.mainTexture;;
            //}
        }

        if (ragdollFlyPrefab)
        {
            GameObject ragdoll = Instantiate(ragdollFlyPrefab, position + Vector3.up * 0.8f, ragdollFlyPrefab.transform.rotation) as GameObject;

            SkinnedMeshRenderer skinRenderer = ragdoll.GetComponentInChildren <SkinnedMeshRenderer>();
            //if (skinRenderer != null)
            //{
            skinRenderer.material.mainTexture = _dependencies.renderer.sharedMaterial.mainTexture;
            //}
        }

        if (Locator.Get <EnemyManager> ().killstreakCounter)
        {
            Locator.Get <EnemyManager> ().killstreakCounter.enemiesKilled += 1;
            Locator.Get <EnemyManager> ().killstreakCounter.countdown      = Locator.Get <EnemyManager> ().killstreakCounter.killTimer;
        }
    }