GetComponents() публичный метод

public GetComponents ( Type type ) : UnityEngine.Component[]
type System.Type
Результат UnityEngine.Component[]
Пример #1
0
    void enablePlayer(GameObject player)
    {
        foreach (MonoBehaviour obj in player.GetComponents<MonoBehaviour>())
            obj.enabled = true;

        foreach (CharacterController obj in player.GetComponents<CharacterController>())
            obj.enabled = true;
    }
Пример #2
0
    private static XmlElement GameObjectToXmlElement(GameObject gameObject, XmlDocument document)
    {
        XmlElement entityElement = document.CreateElement("entity");
        entityElement.SetAttribute("name",gameObject.name);

        Object[] outputComponents = gameObject.GetComponents(typeof(OutputComponent));

        for (int j = 0; j < outputComponents.Length; j++)
        {
            OutputComponent oc = (OutputComponent)outputComponents[j];
            XmlElement outputElement = oc.ToXmlElement(document);

            entityElement.AppendChild(outputElement);
            outputElement.SetAttribute("uid","" + oc.uid);
        }

        for (int i = 0; i < gameObject.transform.GetChildCount(); i++)
        {
            GameObject child = gameObject.transform.GetChild(i).gameObject;

            int childOutputComponents = child.GetComponents(typeof(OutputComponent)).Length;

            if (childOutputComponents > 0)
            {
                XmlElement childXmlElement = GameObjectToXmlElement(child, document);
                entityElement.AppendChild(childXmlElement);
            }
        }

        return entityElement;
    }
Пример #3
0
 void SetVisiible(GameObject obj, bool visible)
 {
     foreach (Renderer component in obj.GetComponents<Renderer>())
     {
         component.enabled = visible;
     }
 }
Пример #4
0
 static public int GetComponents(IntPtr l)
 {
     try {
         int argc = LuaDLL.lua_gettop(l);
         if (argc == 2)
         {
             UnityEngine.GameObject self = (UnityEngine.GameObject)checkSelf(l);
             System.Type            a1;
             checkType(l, 2, out a1);
             var ret = self.GetComponents(a1);
             pushValue(l, true);
             pushValue(l, ret);
             return(2);
         }
         else if (argc == 3)
         {
             UnityEngine.GameObject self = (UnityEngine.GameObject)checkSelf(l);
             System.Type            a1;
             checkType(l, 2, out a1);
             System.Collections.Generic.List <UnityEngine.Component> a2;
             checkType(l, 3, out a2);
             self.GetComponents(a1, a2);
             pushValue(l, true);
             return(1);
         }
         pushValue(l, false);
         LuaDLL.lua_pushstring(l, "No matched override function to call");
         return(2);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
	// Use this for initialization
	void Start () {
		ConsoleLog.SLog ("PlayerGameManager Start()");

		anim = GetComponent<Animator> ();
		cardboardCamera = GameObject.FindGameObjectWithTag("PlayerHead");
		cardboardHead = cardboardCamera.GetComponent<CardboardHead> ();
		headPos = GameObject.FindGameObjectWithTag ("CameraPos").transform;
		gun = GameObject.FindGameObjectWithTag ("MyGun");
		gunProperties = gun.GetComponent<GunProperties> ();
		gunAudio = gun.GetComponents<AudioSource> ();
		gunLight = GameObject.FindGameObjectWithTag ("GunLight");
		gunFlashEmitter = GameObject.FindGameObjectWithTag ("GunFlash").GetComponent<EllipsoidParticleEmitter>();
		gunFlashEmitter.emit = false;
		footstepsAudio = GetComponent<AudioSource> ();
		bulletHoleArray = new ArrayList (bulletHoleMaxAmount);

		//HUD
		HUD = GameObject.FindGameObjectWithTag("HUD");
		healthBar = HUD.transform.GetChild (0) as Transform;
		bulletText = HUD.transform.GetChild (1).GetComponent<TextMesh>();
		reloadText = HUD.transform.GetChild (2).GetComponent<TextMesh>();
		grenadeText = HUD.transform.GetChild (3).GetComponent<TextMesh>();
		HUDCanvas = HUD.transform.GetChild (4).gameObject;
		deadText = HUDCanvas.transform.GetChild (0).gameObject;
		endRoundText = HUDCanvas.transform.GetChild (1).gameObject;
		endGameText = HUDCanvas.transform.GetChild (2).gameObject;

		bulletText.text = gunProperties.bulletLoadCurrent + "/" + gunProperties.bulletStoreCurrent;
		grenadeText.text = grenadeStore + "";
	}
 private static void FindInGO(GameObject g)
 {
     go_count++;
     Component[] components = g.GetComponents<Component>();
     for (int i = 0; i < components.Length; i++)
     {
         components_count++;
         if (components[i] == null)
         {
             missing_count++;
             string s = g.name;
             Transform t = g.transform;
             while (t.parent != null) 
             {
                 s = t.parent.name +"/"+s;
                 t = t.parent;
             }
             Debug.Log (s + " has an empty script attached in position: " + i, g);
         }
     }
     // Now recurse through each child GO (if there are any):
     foreach (Transform childT in g.transform)
     {
         //Debug.Log("Searching " + childT.name  + " " );
         FindInGO(childT.gameObject);
     }
 }
Пример #7
0
    private ItemData CreateItemDataFromGameObject(GameObject gameObject)
    {
        ValidateGameObject (gameObject);

        ItemData itemData = new ItemData ();
        itemData.transformData.position = gameObject.transform.position;
        itemData.transformData.rotation = gameObject.transform.eulerAngles;
        itemData.transformData.scale = gameObject.transform.localScale;
        itemData.name = gameObject.name;

        foreach (IPersistable persistable in gameObject.GetComponents<IPersistable>()) {

          SerializableDictionary<string, object> componentConfiguration = new SerializableDictionary<string, object> ();
          foreach (FieldInfo field in persistable.GetType().GetFields()) {
        componentConfiguration.Add (field.Name, field.GetValue (persistable));
          }

          string componentName = persistable.GetType ().FullName;

          itemData.componentData.configurations.Add (componentName, componentConfiguration);
        }

        foreach (Transform child in gameObject.transform) {
          if (child.GetComponents<IPersistable> ().Length > 0) {
        itemData.children.Add (CreateItemDataFromGameObject (child.gameObject));
          }
        }

        return itemData;
    }
Пример #8
0
 public static void InjectGameObject(DiContainer container, GameObject gameObj)
 {
     foreach (var monoBehaviour in gameObj.GetComponents<MonoBehaviour>())
     {
         InjectMonoBehaviour(container, monoBehaviour);
     }
 }
Пример #9
0
    static int GetComponents(IntPtr L)
    {
        try
        {
            int count = LuaDLL.lua_gettop(L);

            if (count == 2 && TypeChecker.CheckTypes(L, 1, typeof(UnityEngine.GameObject), typeof(System.Type)))
            {
                UnityEngine.GameObject  obj  = (UnityEngine.GameObject)ToLua.ToObject(L, 1);
                System.Type             arg0 = (System.Type)ToLua.ToObject(L, 2);
                UnityEngine.Component[] o    = obj.GetComponents(arg0);
                ToLua.Push(L, o);
                return(1);
            }
            else if (count == 3 && TypeChecker.CheckTypes(L, 1, typeof(UnityEngine.GameObject), typeof(System.Type), typeof(System.Collections.Generic.List <UnityEngine.Component>)))
            {
                UnityEngine.GameObject obj  = (UnityEngine.GameObject)ToLua.ToObject(L, 1);
                System.Type            arg0 = (System.Type)ToLua.ToObject(L, 2);
                System.Collections.Generic.List <UnityEngine.Component> arg1 = (System.Collections.Generic.List <UnityEngine.Component>)ToLua.ToObject(L, 3);
                obj.GetComponents(arg0, arg1);
                return(0);
            }
            else
            {
                return(LuaDLL.luaL_throw(L, "invalid arguments to method: UnityEngine.GameObject.GetComponents"));
            }
        }
        catch (Exception e)
        {
            return(LuaDLL.toluaL_exception(L, e));
        }
    }
Пример #10
0
    /// <summary>
    /// This adds a new target game object. 
    /// </summary>
    /// <param name="gameObject">
    /// The game object to target.
    /// </param>
    public void AddGameObject(GameObject gameObject)
    {
        //make sure this game object is not null and is not already in the list
        if (gameObject != null && targetGameObjects.Contains(gameObject) == false)
        {
            //warn if the game object being added is the parent of this component
            if (gameObject == this)
            {
                Debug.LogWarning("You are adding a game object to a modifier that is the parent of this modifier.  This may have unexpected results.");
            }

            //add the game object
            targetGameObjects.Add(gameObject);

            //get all MonoBehavior components on this target game object
            MonoBehaviour[] behaviours = gameObject.GetComponents<MonoBehaviour>();
            for (int j = 0; j < behaviours.Length; j++)
            {
                //make sure the found behavior is not this behavior, and it is a IVisModifierTarget
                if (behaviours[j] != this && behaviours[j] is IVisModifierTarget)
                {
                    //get the modifier target and add to the ValueUpdate event
                    IVisModifierTarget modifierTarget = behaviours[j] as IVisModifierTarget;
                    if (modifierTarget != null)
                        ValueUpdated += modifierTarget.OnValueUpdated;
                }
            }
        }
    }
Пример #11
0
        /// <summary>
        /// Returns an array of all components attached to the selected GameObject instance, except UnityEngine.Camera and UnityEngine.Transform
        /// </summary>
        private static U.Component[] GatherComponents(U.GameObject selected)
        {
            U.Component[] initialGather = selected.GetComponents <U.Component>();
            U.Component[] finalGather;
            uint          count = 0;

            for (uint i = 0; i < initialGather.Length; i++)
            {
                if (!(initialGather[i] is U.Camera) && !(initialGather[i] is U.Transform) && (initialGather[i] != null))
                {
                    count++;
                }
            }
            finalGather = new U.Component[count];
            count       = 0;
            for (uint i = 0; i < initialGather.Length; i++)
            {
                if (!(initialGather[i] is U.Camera) && !(initialGather[i] is U.Transform) && (initialGather[i] != null))
                {
                    finalGather[count] = initialGather[i];
                    count++;
                }
            }
            return(finalGather);
        }
 static int QPYX_GetComponents_YXQP(IntPtr L_YXQP)
 {
     try
     {
         int QPYX_count_YXQP = LuaDLL.lua_gettop(L_YXQP);
         if (QPYX_count_YXQP == 2)
         {
             UnityEngine.GameObject  QPYX_obj_YXQP  = (UnityEngine.GameObject)ToLua.CheckObject(L_YXQP, 1, typeof(UnityEngine.GameObject));
             System.Type             QPYX_arg0_YXQP = ToLua.CheckMonoType(L_YXQP, 2);
             UnityEngine.Component[] QPYX_o_YXQP    = QPYX_obj_YXQP.GetComponents(QPYX_arg0_YXQP);
             ToLua.Push(L_YXQP, QPYX_o_YXQP);
             return(1);
         }
         else if (QPYX_count_YXQP == 3)
         {
             UnityEngine.GameObject QPYX_obj_YXQP  = (UnityEngine.GameObject)ToLua.CheckObject(L_YXQP, 1, typeof(UnityEngine.GameObject));
             System.Type            QPYX_arg0_YXQP = ToLua.CheckMonoType(L_YXQP, 2);
             System.Collections.Generic.List <UnityEngine.Component> QPYX_arg1_YXQP = (System.Collections.Generic.List <UnityEngine.Component>)ToLua.CheckObject(L_YXQP, 3, typeof(System.Collections.Generic.List <UnityEngine.Component>));
             QPYX_obj_YXQP.GetComponents(QPYX_arg0_YXQP, QPYX_arg1_YXQP);
             return(0);
         }
         else
         {
             return(LuaDLL.luaL_throw(L_YXQP, "invalid arguments to method: UnityEngine.GameObject.GetComponents"));
         }
     }
     catch (Exception e_YXQP)                {
         return(LuaDLL.toluaL_exception(L_YXQP, e_YXQP));
     }
 }
Пример #13
0
        public static string GetGameObjectBehaviors(GameObject gameObject)
        {
            if (gameObject == null)
            {
                return "GameObject is null";
            }

            var components = gameObject.GetComponents<Component>();
            string list = "";
            foreach (var component in components)
            {
                string behaviorString = "";
                UnityEngine.Behaviour behavior = component as UnityEngine.Behaviour;
                if (behavior != null)
                {
                    behaviorString = " (Behavior)";
                    if (!behavior.enabled)
                    {
                        behaviorString += " (disabled)";
                    }
                }
                list += "Type: " + component.GetType() + behaviorString + "\n";
            }
            return list;
        }
Пример #14
0
    public SIHJR_PVFS_Grid(GameObject _boundary, float influenceWidth)
    {
        Collider2D collider = _boundary.GetComponents<Collider2D> () [0];
        _bounds = collider.bounds;
        _left = collider.bounds.min.x;
        _bottom = collider.bounds.min.y;
        _right = collider.bounds.max.x;
        _top = collider.bounds.max.y;
        _influenceWidth = influenceWidth;

        //create new grid
        _gridWidthCellCount = (int)Mathf.Ceil (collider.bounds.size.x / _influenceWidth);
        _gridHeightCellCount = (int)Mathf.Ceil (collider.bounds.size.y / _influenceWidth);
        //Debug.Log ("gridW: " + _gridWidthCellCount + " -- gridH: " + _gridHeightCellCount);
        //Debug.Log ("grid L: " + _left + " -- grid R: " + _right);
        //Debug.Log ("grid Cell Width: " + _influenceWidth);

        _gridArray = new IList[_gridWidthCellCount + 1, _gridHeightCellCount + 1];

        /*
        _particles = new LinkedList<List<List<SIHJR_PVFS_Particle>>>(xCount);
        for (int i = 0; i < xCount; i++) {
            //create list
            _particles[i] = new LinkedList<List<SIHJR_PVFS_Particle>>(yCount);

            for (int j = 0; j < yCount; j++) {
                _particles[j] = new LinkedList<SIHJR_PVFS_Particle>();
            }

            //create nested lists
        }
        */
    }
Пример #15
0
        public static void DumpObject(UnityEngine.GameObject player)
        {
            UnityEngine.Component[] comps  = player.GetComponents <Component>();
            UnityEngine.Component[] Ccomps = player.GetComponentsInChildren <Component>();
            UnityEngine.Component[] Pcomps = player.GetComponentsInParent <Component>();
            foreach (var entry in comps)
            {
                WriteLine($"Name: {entry.name}");
                WriteLine($"\tType: {entry.GetType()}");
                WriteLine($"\tTag: {entry.tag}");
            }
            WriteLine($"--- {comps.Length} ---", true);

            foreach (var entry in Ccomps)
            {
                WriteLine($"Name: {entry.name}");
                WriteLine($"\tType: {entry.GetType()}");
                WriteLine($"\tTag: {entry.tag}");
            }
            WriteLine($"--- {Ccomps.Length} ---", true);

            foreach (var entry in Pcomps)
            {
                WriteLine($"Name: {entry.name}");
                WriteLine($"\tType: {entry.GetType()}");
                WriteLine($"\tTag: {entry.tag}");
            }
            WriteLine($"--- {Pcomps.Length} ---", true);
        }
Пример #16
0
        // NOTE: This method will not return components that are within a GameObjectContext
        public static IEnumerable<Component> GetInjectableComponentsBottomUp(
            GameObject gameObject, bool recursive)
        {
            var context = gameObject.GetComponent<GameObjectContext>();

            if (context != null)
            {
                yield return context;
                yield break;
            }

            if (recursive)
            {
                foreach (Transform child in gameObject.transform)
                {
                    foreach (var component in GetInjectableComponentsBottomUp(child.gameObject, recursive))
                    {
                        yield return component;
                    }
                }
            }

            foreach (var component in gameObject.GetComponents<Component>())
            {
                yield return component;
            }
        }
Пример #17
0
		private void ApplyRecursive(GameObject go)
		{
			foreach(Graphic graphic in go.GetComponents<Graphic>())
				style.Apply(graphic);

			foreach(Selectable selectable in go.GetComponents<Selectable>())
				style.Apply(selectable);

			foreach(Transform t in go.transform)
			{
				if(t.gameObject.GetComponent<pb_GUIStyleApplier>() != null)
					continue;

				ApplyRecursive(t.gameObject);
			}
		}
Пример #18
0
        public static void AddToEntity(EntityManager entityManager, GameObject gameObject, Entity entity)
        {
            var components = gameObject.GetComponents <Component>();

            for (var i = 0; i != components.Length; i++)
            {
                var com       = components[i];
                var proxy     = com as ComponentDataProxyBase;
                var behaviour = com as Behaviour;
                if (behaviour != null && !behaviour.enabled)
                {
                    continue;
                }

                if (!(com is GameObjectEntity) && com != null && proxy == null)
                {
                    entityManager.AddComponentObject(entity, com);
                }

                if (com is GameObjectEntity)
                {
                    var goe = com as GameObjectEntity;
                    goe.m_EntityManager = entityManager;
                    goe.m_Entity        = entity;
                }
            }
        }
Пример #19
0
    //Beware: This assumes that it's safe to just play sounds using free audio sources.
    // It's a replacement for NGUITools.PlaySound
    public static AudioSource PlaySoundOn(AudioClip clip, GameObject go, float volume = 1.0f)
    {
        if (clip == null || go == null)
        {
            return null;
        }

        AudioSource[] sources = go.GetComponents<AudioSource>();
        AudioSource source = null;

        for (int i=0; i<sources.Length; ++i)
        {
            source = sources[i];
            if (!source.isPlaying || source.clip == clip)
            {
                source.PlayClip(clip, volume);
                return source;
            }
        }

        source = go.AddComponent<AudioSource>();
        source.playOnAwake = false;
        source.PlayClip(clip, volume);
        return source;
    }
    private void CacheMethodsForGameObject(GameObject go, System.Type parameterType) {
        List<string> cachedMethods = new List<string>();
        cache[go].Add( parameterType, cachedMethods );

        List<System.Type> addedTypes = new List<System.Type>();
        MonoBehaviour[] behaviours = go.GetComponents<MonoBehaviour>();
        foreach (MonoBehaviour beh in behaviours) {
            System.Type type = beh.GetType();
            if (addedTypes.IndexOf(type) == -1) {
                System.Reflection.MethodInfo[] methods = type.GetMethods(System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.NonPublic);
                foreach (System.Reflection.MethodInfo method in methods) {
                    // Only add variables added by user, i.e. we don't want functions from the base UnityEngine baseclasses or lower
                    string moduleName = method.DeclaringType.Assembly.ManifestModule.Name;
                    if (!moduleName.Contains("UnityEngine") && !moduleName.Contains("mscorlib") &&
                        !method.ContainsGenericParameters && 
                        System.Array.IndexOf(ignoredMethodNames, method.Name) == -1) {
                        System.Reflection.ParameterInfo[] paramInfo = method.GetParameters();
                        if (paramInfo.Length == 0) {
                            cachedMethods.Add(method.Name);
                        }
                        else if (paramInfo.Length == 1 && paramInfo[0].ParameterType == parameterType) {
                            cachedMethods.Add(method.Name);
                        }
                    }
                }
            }
        }
    }
Пример #21
0
 // Pause
 public void PauseParticle(GameObject PSGO)
 {
     ParticleSystem[] ParticleSys;
     ParticleSys = PSGO.GetComponents<ParticleSystem>();
     foreach(ParticleSystem temp in ParticleSys)
         temp.Pause();
 }
Пример #22
0
 // Use this for initialization
 void Start()
 {
     audio = GameObject.FindWithTag("Audio");
     a = audio.GetComponents<AudioSource>();
     m = GameObject.FindWithTag("Contador");
     marcador = m.GetComponent<GUIText>();
 }
Пример #23
0
 public static void FillMethodsList(List<string> methodsList, GameObject go)
 {
     methodsList.Clear();
     MonoBehaviour[] components = go.GetComponents<MonoBehaviour>();
     foreach (MonoBehaviour mb in components)
     {
         Type t = mb.GetType();
         MethodInfo[] mis = t.GetMethods();
         foreach (MethodInfo mi in mis)
         {
             if (mi.ReturnType == typeof(TaskStatus))
             {
                 ParameterInfo[] pis = mi.GetParameters();
                 if (pis.Length == 1)
                 {
                     if (pis[0].ParameterType == typeof(GameObject))
                     {
                         string type = t.ToString();
                         string methodName = mi.Name;
                         string newMethod = type + "." + methodName;
                         methodsList.Add(newMethod);
                     }
                 }
             }
         }
     }
 }
Пример #24
0
	/// <summary>
	/// Collect a list of usable delegates from the specified target game object.
	/// The delegates must be of type "void Delegate()".
	/// </summary>

	static List<Entry> GetMethods (GameObject target)
	{
		MonoBehaviour[] comps = target.GetComponents<MonoBehaviour>();

		List<Entry> list = new List<Entry>();

		for (int i = 0, imax = comps.Length; i < imax; ++i)
		{
			MonoBehaviour mb = comps[i];
			if (mb == null) continue;

			MethodInfo[] methods = mb.GetType().GetMethods(BindingFlags.Instance | BindingFlags.Public);

			for (int b = 0; b < methods.Length; ++b)
			{
				MethodInfo mi = methods[b];

				if (mi.GetParameters().Length == 0 && mi.ReturnType == typeof(void))
				{
					if (mi.Name != "StopAllCoroutines" && mi.Name != "CancelInvoke")
					{
						Entry ent = new Entry();
						ent.target = mb;
						ent.method = mi;
						list.Add(ent);
					}
				}
			}
		}
		return list;
	}
        /// <summary>
        ///   Collects a list of usable routed events from the specified target game object.
        /// </summary>
        /// <param name="target">Game object to get all usable routes events of.</param>
        /// <returns>Usable routed events from the specified target game object.</returns>
        protected override List<Entry> GetApplicableMembers(GameObject target)
        {
            MonoBehaviour[] components = target.GetComponents<MonoBehaviour>();

            List<Entry> list = new List<Entry>();

            foreach (MonoBehaviour monoBehaviour in components)
            {
                if (monoBehaviour == null)
                {
                    continue;
                }

                FieldInfo[] fields = monoBehaviour.GetType().GetFields(BindingFlags.Instance | BindingFlags.Public);

                foreach (FieldInfo info in fields)
                {
                    if (info.FieldType != typeof(ViewEvent))
                    {
                        continue;
                    }

                    Entry entry = new Entry { Target = monoBehaviour, MemberName = info.Name };
                    list.Add(entry);
                }
            }
            return list;
        }
Пример #26
0
    public void Setup(GameObject targetType, int inputNumber)
    {
        if (playerShip != null)
        {
            Destroy(playerShip);
            playerShip = null;
        }

        playerShip = (GameObject)Instantiate(targetType, Vector3.zero, Quaternion.identity);

        var scripts = playerShip.GetComponents<MonoBehaviour>();
        for (int i = 0; i < scripts.Length; i++)
        {
            MonoBehaviour data = scripts[i];
            Controller controller = data as Controller;
            if (controller != null)
            {
                controller.horizontalAxis = "Horizontal"+inputNumber;
                controller.verticalAxis = "Vertical"+inputNumber;
                controller.accelerate = "Accelerate" + inputNumber;
                controller.otherAxis = "Other"+inputNumber;
                controller.AssignCamera(GetComponent<Camera>());

            }
        }
    }
Пример #27
0
        private string ShowComponents(SerializedObject objTarget, GameObject gameObject)
        {
            var targetComponentAssemblyName = objTarget.FindProperty("targetComponentAssemblyName");
            var targetComponentFullname = objTarget.FindProperty("targetComponentFullname");
            var targetComponentText = objTarget.FindProperty("targetComponentText");
            var objComponents = gameObject.GetComponents<Component>();
            var objTypesAssemblynames = (from objComp in objComponents select objComp.GetType().AssemblyQualifiedName).ToList();
            var objTypesName = (from objComp in objComponents select objComp.GetType().Name).ToList();

            int index = objTypesAssemblynames.IndexOf(targetComponentAssemblyName.stringValue);

            index = EditorGUILayout.Popup("Target Component", index, objTypesName.ToArray());

            if (index != -1)
            {
                targetComponentAssemblyName.stringValue = objTypesAssemblynames[index];
                targetComponentFullname.stringValue = objComponents.GetType().FullName;
                targetComponentText.stringValue = objTypesName[index];
            }
            else
            {
                targetComponentAssemblyName.stringValue = null;
            }

            objTarget.ApplyModifiedProperties();

            return targetComponentAssemblyName.stringValue;
        }
        static List <TransitionBase> TransitionOut(UnityEngine.GameObject gameObject, bool isRecursiveCall)
        {
            var transitionBases = gameObject.GetComponents <TransitionBase>();
            var transitionList  = new List <TransitionBase>();
            var callRecursive   = false;

            // transition out transition items.
            foreach (var transitionBase in transitionBases)
            {
                // if first invoked on this gameobject, or don't need to trigger direct transition direct.
                if (transitionBase.isActiveAndEnabled && (isRecursiveCall == false || !transitionBase.TransitionOutConfig.MustTriggerDirect))
                {
                    transitionBase.TransitionOut();
                    transitionList.Add(transitionBase);
                    // if we should transition children then set recursive flag
                    if (transitionBase.TransitionOutConfig.TransitionChildren)
                    {
                        callRecursive = true;
                    }
                }
            }

            // if no transition items, or recursive call then process all child gameobjects
            if (transitionBases.Length == 0 || callRecursive)
            {
                for (var i = 0; i < gameObject.transform.childCount; i++)
                {
                    var transform = gameObject.transform.GetChild(i);
                    transitionList.AddRange(TransitionOut(transform.gameObject, true));
                }
            }

            return(transitionList);
        }
    static int GetComponents(IntPtr L)
    {
        try
        {
            int count = LuaDLL.lua_gettop(L);

            if (count == 2)
            {
                UnityEngine.GameObject  obj  = (UnityEngine.GameObject)ToLua.CheckObject <UnityEngine.GameObject>(L, 1);
                System.Type             arg0 = ToLua.CheckMonoType(L, 2);
                UnityEngine.Component[] o    = obj.GetComponents(arg0);
                ToLua.Push(L, o);
                return(1);
            }
            else if (count == 3)
            {
                UnityEngine.GameObject obj  = (UnityEngine.GameObject)ToLua.CheckObject <UnityEngine.GameObject>(L, 1);
                System.Type            arg0 = ToLua.CheckMonoType(L, 2);
                System.Collections.Generic.List <UnityEngine.Component> arg1 = (System.Collections.Generic.List <UnityEngine.Component>)ToLua.CheckObject(L, 3, TypeTraits <System.Collections.Generic.List <UnityEngine.Component> > .type);
                obj.GetComponents(arg0, arg1);
                return(0);
            }
            else
            {
                return(LuaDLL.luaL_throw(L, "invalid arguments to method: UnityEngine.GameObject.GetComponents"));
            }
        }
        catch (Exception e)
        {
            return(LuaDLL.toluaL_exception(L, e));
        }
    }
        public override void draw(GameObject gameObject, QObjectList objectList, Rect selectionRect, Rect curRect)
        {
            bool foundCustomComponent = false;
            if (ignoreUnityMonobehaviour)
            {
                Component[] components = gameObject.GetComponents<MonoBehaviour>();
                for (int i = components.Length - 1; i >= 0; i--)
                {
                    if (components[i] != null && !components[i].GetType().FullName.Contains("UnityEngine"))
                    {
                        foundCustomComponent = true;
                        break;
                    }
                }
            }
            else
            {
                foundCustomComponent = gameObject.GetComponent<MonoBehaviour>() != null;
            }

            if (foundCustomComponent)
            {
                int ident = Mathf.FloorToInt(selectionRect.x / TREE_STEP_WIDTH) - 1;

                curRect.x      = 1 + ident * TREE_STEP_WIDTH;
                curRect.y      = selectionRect.y;
                curRect.width  = TREE_STEP_WIDTH;
                curRect.height = selectionRect.height;

                GUI.DrawTexture(curRect, gameObject.transform.childCount > 0 ? monoBehaviourIconParentTexture : monoBehaviourIconTexture);
            }
        }
    private string[] GetMethod(GameObject obj)
    {
        List<string> methodName = new List<string>();

        Component[] allComponents = obj.GetComponents<Component>();

        if (allComponents.Length>0){
            foreach( Component comp in allComponents){
                if (comp!=null){
                if (comp.GetType().IsSubclassOf( typeof(MonoBehaviour))){
                    MethodInfo[] methodInfos = comp.GetType().GetMethods();
                    foreach( MethodInfo methodInfo in methodInfos){
                        if ((methodInfo.DeclaringType.Namespace == null) || (!methodInfo.DeclaringType.Namespace.Contains("Unity") && !methodInfo.DeclaringType.Namespace.Contains("System"))){
                            if (methodInfo.IsPublic){
                                methodName.Add( methodInfo.Name );
                            }
                        }

                    }
                }
                }
            }
        }
        //
        return methodName.ToArray();
    }
Пример #32
0
 public void SetAllCollidersStatus(bool active, GameObject box)
 {
     foreach (Collider2D c in box.GetComponents<Collider2D>())
     {
         c.enabled = active;
     }
 }
Пример #33
0
    static int GetComponents(IntPtr L)
    {
#if UNITY_EDITOR
        ToluaProfiler.AddCallRecord("UnityEngine.GameObject.Register");
#endif
        try
        {
            int count = LuaDLL.lua_gettop(L);

            if (count == 2)
            {
                UnityEngine.GameObject  obj  = (UnityEngine.GameObject)ToLua.CheckObject(L, 1, typeof(UnityEngine.GameObject));
                System.Type             arg0 = ToLua.CheckMonoType(L, 2);
                UnityEngine.Component[] o    = obj.GetComponents(arg0);
                ToLua.Push(L, o);
                return(1);
            }
            else if (count == 3)
            {
                UnityEngine.GameObject obj  = (UnityEngine.GameObject)ToLua.CheckObject(L, 1, typeof(UnityEngine.GameObject));
                System.Type            arg0 = ToLua.CheckMonoType(L, 2);
                System.Collections.Generic.List <UnityEngine.Component> arg1 = (System.Collections.Generic.List <UnityEngine.Component>)ToLua.CheckObject(L, 3, typeof(System.Collections.Generic.List <UnityEngine.Component>));
                obj.GetComponents(arg0, arg1);
                return(0);
            }
            else
            {
                return(LuaDLL.luaL_throw(L, "invalid arguments to method: UnityEngine.GameObject.GetComponents"));
            }
        }
        catch (Exception e)
        {
            return(LuaDLL.toluaL_exception(L, e));
        }
    }
Пример #34
0
    public void GrabThis(int id)
    {
        Debug.Log("client grab this " + id.ToString());
        if (id != 0) {
            if (RHClone != null) {
                networkView.RPC("DoppelgangerDestroyThis", RPCMode.AllBuffered, RHClone.networkView.viewID);
                //Network.Destroy(RHClone);
            }
            Jitika = GetComponent<GameInv>().gInv[id];

            RHClone = Network.Instantiate(Jitika, RightHand.transform.position, RightHand.transform.rotation, 0) as GameObject;
            Debug.Log("Grabbing " + RHClone.name);
            RHClone.transform.parent = RightHand.transform;
            RHClone.transform.localPosition = Vector3.zero;
            Debug.Log("Grabbed at " + RightHand.transform.position);
            MonoBehaviour[] scriptComps =  RHClone.GetComponents<MonoBehaviour>();
            foreach (MonoBehaviour script in scriptComps) {
                script.enabled = true;
            }
            networkView.RPC("DoppelgangerGrabThis", RPCMode.AllBuffered, gameObject.networkView.viewID, RHClone.networkView.viewID);
        } else {
            if (RHClone != null) {
                networkView.RPC("DoppelgangerDestroyThis", RPCMode.AllBuffered, RHClone.networkView.viewID);
                //Network.Destroy(RHClone);
            }
        }
    }
Пример #35
0
    void RecursiveCopy(GameObject src, GameObject dst)
    {
        Debug.Log("Copying from " + src.name + " to " + dst.name);

        Component[] src_components = src.GetComponents(typeof(Component));

        foreach (Component comp in src_components) {
          if (comp is Transform || comp is Renderer || comp is Animation)
        continue;

          //Debug.Log("Adding " + comp.GetType().Name + " to " + dst.name);
          Component dst_comp = dst.AddComponent(comp.GetType());

          SerializedObject src_ser_obj = new SerializedObject(comp);
          SerializedObject dst_ser_obj = new SerializedObject(dst_comp);
          src_ser_obj.Update();
          dst_ser_obj.Update();

          SerializedProperty ser_prop = src_ser_obj.GetIterator();

          bool enterChildren = true;
          while (ser_prop.Next(enterChildren)) {
        enterChildren = true;
        string path = ser_prop.propertyPath;

        bool skip = false;
        foreach (string blacklisted_path in propertyBlacklist) {
          if (path.EndsWith(blacklisted_path)) {
            skip = true;
            break;
          }
        }
        if (skip) {
          enterChildren = false;
          continue;
        }

        //Debug.Log(path);
        SerializedProperty dst_ser_prop = dst_ser_obj.FindProperty(path);
        AssignSerializedProperty(ser_prop, dst_ser_prop);
          }

          dst_ser_obj.ApplyModifiedProperties();
        }

        foreach (Transform child_transform in src.transform) {
          GameObject child = child_transform.gameObject;

          string dst_object_name = namePrefix + child.name;
          GameObject dst_object = findChildWithName(dst, dst_object_name);

          if (dst_object == null) {
        Debug.LogWarning("Didn't find matching GameObject for " + child.name);
        continue;
          }

          RecursiveCopy(child, dst_object);
        }
    }
    /// <summary>
    /// Check if a component as a missing script
    /// </summary>
    /// <param name="obj">Object to check</param>
    /// <returns>True if there is at least one missing component</returns>
    private bool CheckForMissingScripts(GameObject obj)
    {
        if (obj == null)
            return false;

        Component[] components = obj.GetComponents<Component>();
        return components != null ? components.Any(c => c == null) : false;
    }
Пример #37
0
 public void PlayClip( AudioClip clip)
 {
     SoundManager = GameObject.Find ("SoundManager");
     Audio = SoundManager.GetComponents<AudioSource> ();
     SFX = Audio [1];
     SFX.clip = clip;
     SFX.Play ();
 }
Пример #38
0
	void SetCollidable( GameObject obj, bool collidable )
	{
		foreach( Collider component in obj.GetComponents<Collider>() )
			component.enabled = collidable;
	
		foreach( Collider child in obj.GetComponentsInChildren<Collider>() )
			child.enabled = collidable;
	}
Пример #39
0
        public static Component GetComponentNoAlloc(this UnityEngine.GameObject @this, Type componentType)
        {
            @this.GetComponents(componentType, ComponentCache);
            var component = ComponentCache.Count > 0 ? ComponentCache[0] : null;

            ComponentCache.Clear();
            return(component);
        }
Пример #40
0
 // Disables all scripts in the child objects
 void disableAll(GameObject cam)
 {
     // Disable the object
     cam.SetActive(false);
     foreach (Behaviour comp in cam.GetComponents<Behaviour>()) {
         comp.enabled = false;
     }
 }
Пример #41
0
        public static T GetComponentNoAlloc <T>(this UnityEngine.GameObject @this) where T : Component
        {
            @this.GetComponents(typeof(T), ComponentCache);
            var component = ComponentCache.Count > 0 ? ComponentCache[0] : null;

            ComponentCache.Clear();
            return(component as T);
        }
Пример #42
0
 public static void CopyAllComponentsToEntity(GameObject gameObject, EntityManager entityManager, Entity entity)
 {
     foreach (var proxy in gameObject.GetComponents <ComponentDataProxyBase>())
     {
         // TODO: handle shared components and tag components
         var type = proxy.GetComponentType();
         entityManager.AddComponent(entity, type);
         proxy.UpdateComponentData(entityManager, entity);
     }
 }
Пример #43
0
 static public int GetComponents(IntPtr l)
 {
     try {
                     #if DEBUG
         var    method     = System.Reflection.MethodBase.GetCurrentMethod();
         string methodName = GetMethodName(method);
                     #if UNITY_5_5_OR_NEWER
         UnityEngine.Profiling.Profiler.BeginSample(methodName);
                     #else
         Profiler.BeginSample(methodName);
                     #endif
                     #endif
         int argc = LuaDLL.lua_gettop(l);
         if (argc == 2)
         {
             UnityEngine.GameObject self = (UnityEngine.GameObject)checkSelf(l);
             System.Type            a1;
             checkType(l, 2, out a1);
             var ret = self.GetComponents(a1);
             pushValue(l, true);
             pushValue(l, ret);
             return(2);
         }
         else if (argc == 3)
         {
             UnityEngine.GameObject self = (UnityEngine.GameObject)checkSelf(l);
             System.Type            a1;
             checkType(l, 2, out a1);
             System.Collections.Generic.List <UnityEngine.Component> a2;
             checkType(l, 3, out a2);
             self.GetComponents(a1, a2);
             pushValue(l, true);
             return(1);
         }
         pushValue(l, false);
         LuaDLL.lua_pushstring(l, "No matched override function GetComponents to call");
         return(2);
     }
     catch (Exception e) {
         return(error(l, e));
     }
             #if DEBUG
     finally {
                     #if UNITY_5_5_OR_NEWER
         UnityEngine.Profiling.Profiler.EndSample();
                     #else
         Profiler.EndSample();
                     #endif
     }
             #endif
 }
Пример #44
0
    public static T[] FindComponents <T>(this UnityEngine.GameObject g, bool in_parent = true, bool in_children = true, int sibling_depth = 0, bool ignore_self = false) where T : Component
    {
        HashSet <T> components = new HashSet <T>();

        if (ignore_self)
        {
            if (in_children)
            {
                foreach (Transform child in g.transform)
                {
                    components.Concat(child.GetComponentsInChildren <T>());
                }
            }
            if (in_parent)
            {
                components.Concat(g.transform.parent.GetComponentsInParent <T>());
            }

            return(components.ToArray());
        }

        if (!in_children && !in_parent)
        {
            return(g.GetComponents <T>());
        }
        if (in_children)
        {
            components.Concat(g.GetComponentsInChildren <T>());
        }
        if (in_parent && g.transform.parent)
        {
            components.Concat(g.transform.parent.GetComponentsInParent <T>());
        }

        GameObject current = g;
        GameObject last    = g;

        while (sibling_depth > 0)
        {
            current = current.transform.parent.gameObject;
            if (!current)
            {
                break;
            }
            components.Concat(current.GetComponentsInChildren <T>());
            sibling_depth--;
        }

        return(components.ToArray());
    }
Пример #45
0
 static public int GetComponents__Type(IntPtr l)
 {
     try {
         UnityEngine.GameObject self = (UnityEngine.GameObject)checkSelf(l);
         System.Type            a1;
         checkType(l, 2, out a1);
         var ret = self.GetComponents(a1);
         pushValue(l, true);
         pushValue(l, ret);
         return(2);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
Пример #46
0
 static void OnSelectionChange()
 {
     if (selected == UnityEditor.Selection.activeGameObject)
     {
         return;
     }
     if (selected != null)
     {
         new List <DebuggerIListener>(selected.GetComponents <DebuggerIListener>()).ForEach(x => x.BlurDebug());
     }
     selected = UnityEditor.Selection.activeGameObject;
     if (selected != null)
     {
         new List <DebuggerIListener>(selected.GetComponents <DebuggerIListener>()).ForEach(x => x.FocusDebug());
     }
 }
Пример #47
0
 static public int GetComponents__Type__List_1_Component(IntPtr l)
 {
     try {
         UnityEngine.GameObject self = (UnityEngine.GameObject)checkSelf(l);
         System.Type            a1;
         checkType(l, 2, out a1);
         System.Collections.Generic.List <UnityEngine.Component> a2;
         checkType(l, 3, out a2);
         self.GetComponents(a1, a2);
         pushValue(l, true);
         return(1);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
Пример #48
0
 public static int GetComponents_wrap(long L)
 {
     try
     {
         long nThisPtr = FCLibHelper.fc_get_inport_obj_ptr(L);
         UnityEngine.GameObject  obj  = get_obj(nThisPtr);
         System.Type             arg0 = FCGetObj.GetObj <System.Type>(FCLibHelper.fc_get_wrap_objptr(L, 0));
         UnityEngine.Component[] ret  = obj.GetComponents(arg0);
         long ret_ptr = FCLibHelper.fc_get_return_ptr(L);
         FCCustomParam.ReturnArray(ret, ret_ptr);
     }
     catch (Exception e)
     {
         Debug.LogException(e);
     }
     return(0);
 }
Пример #49
0
 public static int GetComponents1_wrap(long L)
 {
     try
     {
         long nThisPtr = FCLibHelper.fc_get_inport_obj_ptr(L);
         UnityEngine.GameObject       obj  = get_obj(nThisPtr);
         System.Type                  arg0 = FCGetObj.GetObj <System.Type>(FCLibHelper.fc_get_wrap_objptr(L, 0));
         List <UnityEngine.Component> arg1 = null;
         arg1 = FCCustomParam.GetList(ref arg1, L, 1);
         obj.GetComponents(arg0, arg1);
     }
     catch (Exception e)
     {
         Debug.LogException(e);
     }
     return(0);
 }
Пример #50
0
        private CrossEngineImpl.Component[] GetComponentsImpl(System.Type type, bool bGetComponentInChildren)
        {
            CrossEngineImpl.GameObject gobject = GetImpl <CrossEngineImpl.Component>().gameObject;
            if (gobject == null)
            {
                return(null);
            }

            if (bGetComponentInChildren)
            {
                return(gobject.GetComponents(type));
            }
            else
            {
                return(gobject.GetComponentsInChildren(type));
            }
        }
Пример #51
0
        static void GetComponents(GameObject gameObject, bool includeGameObjectComponents, out ComponentType[] types, out Component[] components)
        {
            components = gameObject.GetComponents <Component>();

            var componentCount = 0;

            for (var i = 0; i != components.Length; i++)
            {
                var com           = components[i];
                var componentData = com as ComponentDataProxyBase;

                if (com == null)
                {
                    UnityEngine.Debug.LogWarning($"The referenced script is missing on {gameObject.name}", gameObject);
                }
                else if (componentData != null)
                {
                    componentCount++;
                }
                else if (includeGameObjectComponents && !(com is GameObjectEntity))
                {
                    componentCount++;
                }
            }

            types = new ComponentType[componentCount];

            var t = 0;

            for (var i = 0; i != components.Length; i++)
            {
                var com           = components[i];
                var componentData = com as ComponentDataProxyBase;

                if (componentData != null)
                {
                    types[t++] = componentData.GetComponentType();
                }
                else if (includeGameObjectComponents && !(com is GameObjectEntity) && com != null)
                {
                    types[t++] = com.GetType();
                }
            }
        }
Пример #52
0
        // TODO: move somewhere else
        internal static bool GameObjectContainsAttribute <T>(GameObject go) where T : Attribute
        {
            var behaviours = go.GetComponents(typeof(Component));

            for (var index = 0; index < behaviours.Length; index++)
            {
                var behaviour = behaviours[index];
                if (behaviour == null)
                {
                    continue;
                }

                var behaviourType = behaviour.GetType();
                if (behaviourType.GetCustomAttributes(typeof(T), true).Length > 0)
                {
                    return(true);
                }
            }
            return(false);
        }
Пример #53
0
 static public int GetComponents(IntPtr l)
 {
     try{
         if (matchType(l, 2, typeof(System.Type)))
         {
             UnityEngine.GameObject self = (UnityEngine.GameObject)checkSelf(l);
             System.Type            a1;
             checkType(l, 2, out a1);
             UnityEngine.Component[] ret = self.GetComponents(a1);
             pushValue(l, ret);
             return(1);
         }
         LuaDLL.luaL_error(l, "No matched override function to call");
         return(0);
     }
     catch (Exception e) {
         LuaDLL.luaL_error(l, e.ToString());
         return(0);
     }
 }
        static void GetComponents(GameObject gameObject, bool includeGameObjectComponents, out ComponentType[] types, out Component[] components)
        {
            components = gameObject.GetComponents <Component>();

            var componentCount = 0;

            if (includeGameObjectComponents)
            {
                var gameObjectEntityComponent = gameObject.GetComponent <GameObjectEntity>();
                componentCount = gameObjectEntityComponent == null ? components.Length : components.Length - 1;
            }
            else
            {
                for (var i = 0; i != components.Length; i++)
                {
                    if (components[i] is ComponentDataWrapperBase)
                    {
                        componentCount++;
                    }
                }
            }

            types = new ComponentType[componentCount];

            var t = 0;

            for (var i = 0; i != components.Length; i++)
            {
                var com           = components[i];
                var componentData = com as ComponentDataWrapperBase;

                if (componentData != null)
                {
                    types[t++] = componentData.GetComponentType();
                }
                else if (includeGameObjectComponents && !(com is GameObjectEntity))
                {
                    types[t++] = com.GetType();
                }
            }
        }
Пример #55
0
 public static Component[] GetComponents0T(this UnityEngine.GameObject self, System.Type T)
 {
     return(self.GetComponents(T));
 }
Пример #56
0
        public override void OnInspectorGUI()
        {
            Renderer renderer = _rootGameObj.renderer;

            if (renderer)
            {
                _oldSortingLayerIdx = _layerIds.FindIndex(x => x == renderer.sortingLayerID);
                _oldSortingOrder    = renderer.sortingOrder;

                Renderer[] testRenderers = _rootGameObj.GetComponents <Renderer>();
                if (testRenderers.Length > 1)
                {
                    EditorGUILayout.LabelField("More renderers found. Using " + renderer.GetType());
                }
            }
            else
            {
                EditorGUILayout.LabelField("No renderer found on this gameObject.");
            }

            if (_layerNames.Count == 0)
            {
                EditorGUILayout.LabelField("Can't get renderer information!");
                return;
            }

            _target.SortingOrderOffsetEnabled = EditorGUILayout.ToggleLeft("Sorting Order Offset Enabled", _target.SortingOrderOffsetEnabled);

            int newlayerIdx = EditorGUILayout.Popup("Sorting Layer ", _oldSortingLayerIdx, _layerNames.ToArray());

            if (renderer && newlayerIdx != _oldSortingLayerIdx)
            {
                Undo.RecordObject(renderer, "Edit Sorting Layer ID");
                renderer.sortingLayerName = _layerNames[newlayerIdx];
                EditorUtility.SetDirty(renderer);
            }
            _oldSortingLayerIdx = newlayerIdx;

            int newSortingLayerOrder = EditorGUILayout.IntField("Sorting Layer Order", _oldSortingOrder);

            if (renderer && newSortingLayerOrder != _oldSortingOrder)
            {
                Undo.RecordObject(renderer, "Edit Sorting Order");
                renderer.sortingOrder = newSortingLayerOrder;
                EditorUtility.SetDirty(renderer);
            }
            _oldSortingOrder = newSortingLayerOrder;

            if (newlayerIdx >= 0)
            {
                _target.SetDefaults(_layerIds[newlayerIdx], newSortingLayerOrder);
            }

            /*
             *              if (GUILayout.Button("Apply to all children with hiearchy order + 1"))
             *              {
             *                      if (EditorUtility.DisplayDialog("Are you sure?", "All sorting layers and orders in all children will be overwritten!", "Yes", "No"))
             *                      {
             *                              Undo.RecordObject(_rootGameObj, "Apply to Children Sorting Layers and Orders");
             *                              SortingLayer.SetDeepIncreasedOrder(_rootGameObj, _layerNames[newlayerIdx], newSortingLayerOrder);
             *                      }
             *              }
             */
            if (GUILayout.Button("Apply sorting layer to all children. Keep order."))
            {
                if (EditorUtility.DisplayDialog("Are you sure?", "All sorting layers in all children will be overwritten!", "Yes", "No"))
                {
/*
 *                                      foreach(GameObject selected in Selection.gameObjects)
 *                                              SortingLayer.SetDeepStaticOrder(selected, _layerNames[newlayerIdx]);
 */
                    Undo.RecordObject(_rootGameObj, "Apply to Children Sorting Layers");
                    SortingLayer.SetDeepStaticOrder(_rootGameObj, _layerNames[newlayerIdx], false);
                }
            }

            int deltaOrder = 1000;

            if (GUILayout.Button("Change sorting layer order by " + deltaOrder + " to all children. Keep layer."))
            {
                if (EditorUtility.DisplayDialog("Are you sure?", "All sorting layer orders in all children will be overwritten!", "Yes", "No"))
                {
                    Undo.RecordObject(_rootGameObj, "Apply to Children Sorting Layer Orders " + deltaOrder);
                    SortingLayer.SetDeepDeltaOrder(_rootGameObj, deltaOrder, false);
                    _oldSortingOrder = _oldSortingOrder + deltaOrder;
                }
            }
        }
Пример #57
0
    /// <summary>
    /// Given an immovable fragment, destroy it by simulating an explosion. The explosion will be
    /// considered as a sphere. The fragment will be given a rigid body and will be moved accordingly.
    /// </summary>
    /// <param name="fragment">Immovable fragment to be destroyed.</param>
    /// <param name="hitPoint">Explosion center.</param>
    /// <param name="radius">Explosion radius (must be positive).</param>
    /// <param name="force">Explosion force (must be positive).</param>
    private static void DestroyFragment(GameObject fragment, Vector3 hitPoint, float radius, float force, bool immidiateHingeBreak = false)
    {
        if (fragment == null)
        {
            throw new System.ArgumentNullException("fragment");
        }
        if (!fragment.CompareTag(Constants.FrozenFragmentStr))
        {
            throw new System.ArgumentException("Fragment is not tagged frozen");
        }
        if (radius <= 0.0f)
        {
            throw new System.ArgumentException("Radius is not greater than 0.0");
        }
        if (force <= 0.0f)
        {
            throw new System.ArgumentException("Force is not greater than 0.0");
        }

        fragment.name  = Constants.MovingFragmentStr + fragment.name.Substring(Constants.FrozenFragmentStr.Length);
        fragment.tag   = Constants.MovingFragmentStr;
        fragment.layer = LayerMask.NameToLayer(Constants.MovingFragmentStr);

        Rigidbody rb = fragment.GetComponent <Rigidbody>();

        if (rb == null)
        {
            rb = fragment.AddComponent <Rigidbody>();
        }
        rb.angularDrag = 0.0f;
        rb.drag        = 0.0f;
        rb.AddExplosionForce(force, hitPoint, radius);
        Object.Destroy(fragment.GetComponent <JointBreakListener>());


        if (immidiateHingeBreak)
        {
            HingeJoint[] hingeJoints = fragment.GetComponents <HingeJoint>();
            foreach (HingeJoint hingeJoint in hingeJoints)
            {
                GameObject neighbour = hingeJoint.connectedBody.gameObject;
                Debug.Log($"Checking hinge {fragment.name} -> {neighbour.name}");
                HingeJoint[] neighHingeJoints = neighbour.GetComponents <HingeJoint>();
                foreach (HingeJoint neighHingeJoint in neighHingeJoints)
                {
                    //Debug.Log($"\t Checking {neighbour.name}'s hinge with {neighHingeJoint.connectedBody.name}");
                    if (neighHingeJoint.connectedBody.gameObject == fragment)
                    {
                        Debug.Log($"\t\t Destroyed hinge {neighHingeJoint.gameObject.name} -> {fragment.name}");
                        Object.DestroyImmediate(neighHingeJoint);
                        break;
                    }
                }
                Object.DestroyImmediate(hingeJoint);
            }
        }


        rb.isKinematic            = false;
        fragment.transform.parent = null;
        Object.Destroy(fragment, Random.Range(Constants.FragmentMinDestroyDelay, Constants.FragmentMaxDestroyDelay));
    }
Пример #58
0
 public Component[] GetComponents(Type type)
 {
     return(gameObject.GetComponents(type));
 }
Пример #59
0
 public void CardClick(UnityEngine.GameObject go)
 {
     if (effectPlay)
     {
         PlayEffect(go);
         effectPlay = false;
     }
     if (!firstclicked)
     {
         firstclicked = true;
         if (positionOK)
         {
             positionOK = false;
             int i;
             if (int.TryParse(go.transform.name, out i))
             {
                 Clickwhich = i;
                 //           UnityEngine.Transform tf = transform.Find(i.ToString());
                 //           if (tf != null) {
                 TweenRotation tr = /*tf.gameObject*/ go.GetComponents <TweenRotation>()[0];
                 if (tr != null)
                 {
                     tr.PlayForward();
                 }
                 //}
             }
             UnityEngine.Transform tfc = transform.Find("ExtractNum");
             if (tfc != null)
             {
                 UILabel ul = tfc.gameObject.GetComponent <UILabel>();
                 if (ul != null)
                 {
                     ul.text = ArkCrossEngine.StrDictionaryProvider.Instance.Format(136, 0);
                 }
             }
         }
         for (int m = 0; m < 4; ++m)
         {
             UnityEngine.Transform tf = transform.Find(m.ToString());
             if (tf != null)
             {
                 UnityEngine.BoxCollider bc = tf.gameObject.GetComponent <UnityEngine.BoxCollider>();
                 if (bc != null)
                 {
                     bc.enabled = false;
                 }
             }
         }
     }
     else
     {
         if (go != null)
         {
             TweenRotation tr = go.GetComponents <TweenRotation>()[0];
             if (tr != null)
             {
                 tr.PlayForward();
             }
         }
     }
 }
        /// <summary>
        /// Returns whether the specified gameobject contains any transitions.
        /// </summary>
        /// <param name="gameObject"></param>
        /// <returns></returns>
        public static bool ContainsTransition(UnityEngine.GameObject gameObject)
        {
            var transitionBases = gameObject.GetComponents <TransitionBase>();

            return(transitionBases.Length != 0);
        }