UnityEngine.GameObject.AddComponent()

Here are the examples of the csharp api UnityEngine.GameObject.AddComponent() taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

638 Examples 7

19 Source : NGUITools.cs
with Apache License 2.0
from 365082218

static public AudioSource PlaySound (AudioClip clip, float volume, float pitch)
	{
		volume *= soundVolume;

		if (clip != null && volume > 0.01f)
		{
			if (mListener == null)
			{
				mListener = GameObject.FindObjectOfType(typeof(AudioListener)) as AudioListener;

				if (mListener == null)
				{
					Camera cam = Camera.main;
					if (cam == null) cam = GameObject.FindObjectOfType(typeof(Camera)) as Camera;
					if (cam != null) mListener = cam.gameObject.AddComponent<AudioListener>();
				}
			}

			if (mListener != null && mListener.enabled && NGUITools.GetActive(mListener.gameObject))
			{
				AudioSource source = mListener.GetComponent<AudioSource>();
				if (source == null) source = mListener.gameObject.AddComponent<AudioSource>();
				source.pitch = pitch;
				source.PlayOneShot(clip, volume);
				return source;
			}
		}
		return null;
	}

19 Source : UICharacterSelect_Unit.cs
with Apache License 2.0
from 365082218

protected CanvasGroup GetDeleteButtonCavnasGroup()
		{
			if (this.deleteButton != null)
			{
				CanvasGroup cg = this.deleteButton.gameObject.GetComponent<CanvasGroup>();
				return (cg == null) ? this.deleteButton.gameObject.AddComponent<CanvasGroup>() : cg;
			}
			
			return null;
		}

19 Source : UILoadingBar_OverlayFinish.cs
with Apache License 2.0
from 365082218

protected void Start()
		{
			if (this.targetImage == null || this.bar == null)
			{
				Debug.LogWarning(this.GetType() + " requires target Image and Test_LoadingBar in order to work.", this);
				this.enabled = false;
				return;
			}
			
			// Make sure our finish has canvas group
			if (this.autoVisibility)
			{
				this.canvasGroup = this.targetImage.gameObject.GetComponent<CanvasGroup>();
				if (this.canvasGroup == null) this.canvasGroup = this.targetImage.gameObject.AddComponent<CanvasGroup>();
				
				// Get the default alpha of the target widget
				this.defaultFinishAlpha = this.canvasGroup.alpha;
				
				// check if we need to hide the finish
				if (this.showAfterPct > 0f)
					this.canvasGroup.alpha = (this.targetImage.fillAmount < this.showAfterPct) ? 0f : 1f;
			}
			
			// Make sure the image anchor is left
			this.targetImage.rectTransform.anchorMin = new Vector2(0f, this.targetImage.rectTransform.anchorMin.y);
			this.targetImage.rectTransform.anchorMax = new Vector2(0f, this.targetImage.rectTransform.anchorMax.y);
			
			// Get the default with of the target widget
			this.defaultFinishWidth = this.targetImage.rectTransform.rect.width;
			
			// Hook on change event
			this.bar.onChange.AddListener(OnBarFillChange);
		}

19 Source : UISlotBaseEditor.cs
with Apache License 2.0
from 365082218

protected void DrawHoverProperties()
		{
			EditorGUILayout.LabelField("Hovered State Properties", EditorStyles.boldLabel);
			EditorGUI.indentLevel = (EditorGUI.indentLevel + 1);
			
			EditorGUILayout.PropertyField(this.hoverTargetGraphicProperty, new GUIContent("Target Graphic"));
			EditorGUILayout.PropertyField(this.hoverTransitionProperty, new GUIContent("Transition"));
			
			Graphic graphic = this.hoverTargetGraphicProperty.objectReferenceValue as Graphic;
			UISlotBase.Transition transition = (UISlotBase.Transition)this.hoverTransitionProperty.enumValueIndex;
			
			if (transition != UISlotBase.Transition.None)
			{
				EditorGUI.indentLevel = (EditorGUI.indentLevel + 1);
				
				if (transition == UISlotBase.Transition.ColorTint)
				{
					if (graphic == null)
					{
						EditorGUILayout.HelpBox("You must have a Graphic target in order to use a color transition.", MessageType.Info);
					}
					else
					{
						EditorGUI.BeginChangeCheck();
						EditorGUILayout.PropertyField(this.hoverNormalColorProperty, new GUIContent("Normal"));
						if (EditorGUI.EndChangeCheck())
							graphic.canvasRenderer.SetColor(this.hoverNormalColorProperty.colorValue);
							
						EditorGUILayout.PropertyField(this.hoverHighlightColorProperty, new GUIContent("Highlighted"));
						EditorGUILayout.PropertyField(this.hoverTransitionDurationProperty, new GUIContent("Duration"));
					}
				}
				else if (transition == UISlotBase.Transition.SpriteSwap)
				{
					if (graphic as Image == null)
					{
						EditorGUILayout.HelpBox("You must have a Image target in order to use a sprite swap transition.", MessageType.Info);
					}
					else
					{
						EditorGUILayout.PropertyField(this.hoverOverrideSpriteProperty, new GUIContent("Override Sprite"));
					}
				}
				else if (transition == UISlotBase.Transition.Animation)
				{
					if (graphic == null)
					{
						EditorGUILayout.HelpBox("You must have a Graphic target in order to use a animation transition.", MessageType.Info);
					}
					else
					{
						EditorGUILayout.PropertyField(this.hoverNormalTriggerProperty, new GUIContent("Normal"));
						EditorGUILayout.PropertyField(this.hoverHighlightTriggerProperty, new GUIContent("Highlighted"));
						
						Animator animator = graphic.gameObject.GetComponent<Animator>();
						
						if (animator == null || animator.runtimeAnimatorController == null)
						{
							Rect controlRect = EditorGUILayout.GetControlRect();
							controlRect.xMin = (controlRect.xMin + EditorGUIUtility.labelWidth);
							
							if (GUI.Button(controlRect, "Auto Generate Animation", EditorStyles.miniButton))
							{
								// Generate the animator controller
								UnityEditor.Animations.AnimatorController animatorController = this.GenerateHoverAnimatorController();
								
								if (animatorController != null)
								{
									if (animator == null)
									{
										animator = graphic.gameObject.AddComponent<Animator>();
									}
									UnityEditor.Animations.AnimatorController.SetAnimatorController(animator, animatorController);
								}
							}
						}
					}
				}
				
				EditorGUI.indentLevel = (EditorGUI.indentLevel - 1);
			}
			
			EditorGUI.indentLevel = (EditorGUI.indentLevel - 1);
		}

19 Source : UISlotBaseEditor.cs
with Apache License 2.0
from 365082218

protected void DrawPressProperties()
		{
			EditorGUILayout.LabelField("Pressed State Properties", EditorStyles.boldLabel);
			EditorGUI.indentLevel = (EditorGUI.indentLevel + 1);
			
			EditorGUILayout.PropertyField(this.pressTargetGraphicProperty, new GUIContent("Target Graphic"));
			EditorGUILayout.PropertyField(this.pressTransitionProperty, new GUIContent("Transition"));
			
			Graphic graphic = this.pressTargetGraphicProperty.objectReferenceValue as Graphic;
			UISlotBase.Transition transition = (UISlotBase.Transition)this.pressTransitionProperty.enumValueIndex;
			
			if (transition != UISlotBase.Transition.None)
			{
				EditorGUI.indentLevel = (EditorGUI.indentLevel + 1);
				
				if (transition == UISlotBase.Transition.ColorTint)
				{
					if (graphic == null)
					{
						EditorGUILayout.HelpBox("You must have a Graphic target in order to use a color transition.", MessageType.Info);
					}
					else
					{
						EditorGUI.BeginChangeCheck();
						EditorGUILayout.PropertyField(this.pressNormalColorProperty, new GUIContent("Normal"));
						if (EditorGUI.EndChangeCheck())
							graphic.canvasRenderer.SetColor(this.pressNormalColorProperty.colorValue);
							
						EditorGUILayout.PropertyField(this.pressPressColorProperty, new GUIContent("Pressed"));
						EditorGUILayout.PropertyField(this.pressTransitionDurationProperty, new GUIContent("Duration"));
						EditorGUIUtility.labelWidth = 150f;
						EditorGUILayout.PropertyField(this.pressTransitionInstaOutProperty, new GUIContent("Instant Out"));
						EditorGUIUtility.labelWidth = 120f;
					}
				}
				else if (transition == UISlotBase.Transition.SpriteSwap)
				{
					if (graphic as Image == null)
					{
						EditorGUILayout.HelpBox("You must have a Image target in order to use a sprite swap transition.", MessageType.Info);
					}
					else
					{
						EditorGUILayout.PropertyField(this.pressOverrideSpriteProperty, new GUIContent("Override Sprite"));
					}
				}
				else if (transition == UISlotBase.Transition.Animation)
				{
					if (graphic == null)
					{
						EditorGUILayout.HelpBox("You must have a Graphic target in order to use a animation transition.", MessageType.Info);
					}
					else
					{
						EditorGUILayout.PropertyField(this.pressNormalTriggerProperty, new GUIContent("Normal"));
						EditorGUILayout.PropertyField(this.pressPressTriggerProperty, new GUIContent("Pressed"));
						
						Animator animator = graphic.gameObject.GetComponent<Animator>();
						
						if (animator == null || animator.runtimeAnimatorController == null)
						{
							Rect controlRect = EditorGUILayout.GetControlRect();
							controlRect.xMin = (controlRect.xMin + EditorGUIUtility.labelWidth);
							
							if (GUI.Button(controlRect, "Auto Generate Animation", EditorStyles.miniButton))
							{
								// Generate the animator controller
								UnityEditor.Animations.AnimatorController animatorController = this.GeneratePressAnimatorController();
								
								if (animatorController != null)
								{
									if (animator == null)
									{
										animator = graphic.gameObject.AddComponent<Animator>();
									}
									UnityEditor.Animations.AnimatorController.SetAnimatorController(animator, animatorController);
								}
							}
						}
					}
				}
				
				EditorGUIUtility.labelWidth = 150f;
				EditorGUILayout.PropertyField(this.pressForceHoverNormalProperty, new GUIContent("Force Hover Normal"));
				EditorGUIUtility.labelWidth = 120f;
				EditorGUI.indentLevel = (EditorGUI.indentLevel - 1);
			}
			
			EditorGUI.indentLevel = (EditorGUI.indentLevel - 1);
		}

19 Source : UITabEditor.cs
with Apache License 2.0
from 365082218

private void DrawTargetImageProperties()
		{
			EditorGUILayout.LabelField("Image Target Properties", EditorStyles.boldLabel);
			EditorGUI.indentLevel = (EditorGUI.indentLevel + 1);
			
			EditorGUILayout.PropertyField(this.m_ImageTargetProperty);
			
			// Check if image is set
			if (this.m_ImageTargetProperty.objectReferenceValue != null)
			{
				Image image = (this.m_ImageTargetProperty.objectReferenceValue as Image);
				
				EditorGUILayout.PropertyField(this.m_ImageTransitionProperty);
				
				// Get the selected transition
				Selectable.Transition transition = (Selectable.Transition)this.m_ImageTransitionProperty.enumValueIndex;
				
				if (transition != Selectable.Transition.None)
				{
					EditorGUI.indentLevel = (EditorGUI.indentLevel + 1);
					if (transition == Selectable.Transition.ColorTint)
					{
						EditorGUILayout.PropertyField(this.m_ImageColorsProperty);
					}
					else if (transition == Selectable.Transition.SpriteSwap)
					{
						EditorGUILayout.PropertyField(this.m_ImageSpriteStateProperty);
					}
					else if (transition == Selectable.Transition.Animation)
					{
						EditorGUILayout.PropertyField(this.m_ImageAnimationTriggersProperty);
						
						Animator animator = image.gameObject.GetComponent<Animator>();
						
						if (animator == null || animator.runtimeAnimatorController == null)
						{
							Rect controlRect = EditorGUILayout.GetControlRect();
							controlRect.xMin = (controlRect.xMin + EditorGUIUtility.labelWidth);
							
							if (GUI.Button(controlRect, "Auto Generate Animation", EditorStyles.miniButton))
							{
								// Generate the animator controller
								UnityEditor.Animations.AnimatorController animatorController = UIAnimatorControllerGenerator.GenerateAnimatorContoller(this.m_ImageAnimationTriggersProperty, this.target.name);
								
								if (animatorController != null)
								{
									if (animator == null)
									{
										animator = image.gameObject.AddComponent<Animator>();
									}
									UnityEditor.Animations.AnimatorController.SetAnimatorController(animator, animatorController);
								}
							}
						}
					}
					EditorGUI.indentLevel = (EditorGUI.indentLevel - 1);
				}
			}
			
			EditorGUI.indentLevel = (EditorGUI.indentLevel - 1);
		}

19 Source : ModifyGameItem.cs
with GNU General Public License v3.0
from a2659802

private IEnumerator Start()
            {
                yield return new WaitForSceneLoadFinish();
                Scene s = USceneManager.GetActiveScene();
                foreach (var g in s.GetRootGameObjects())
                {
                    if (g.name.Contains("_Transition") || g.layer == (int)GlobalEnums.PhysLayers.TRANSITION_GATES || g.GetComponent<TransitionPoint>()!=null)
                    {
                        if(SetupMode)
                            g.gameObject.AddComponent<ShowColliders>();
                        Logger.LogDebug($"Skip gate object:{g.name}");
                        continue;
                    }
                    if (g.GetComponent<CustomDecoration>() != null)
                        continue;
                    Destroy(g.gameObject);
                }
                UnVisableBehaviour.AttackReact.Create(gameObject);
            }

19 Source : GUIDrawer.cs
with GNU General Public License v3.0
from aelariane

public void Enable()
        {
            if (drawer != null)
            {
                return;
            }
            drawer = new GameObject(owner.Name + "_DrawerObject").AddComponent<GUIDrawerObject>();
            drawer.layer = -1;
            drawer.owner = this;
            drawer.Cancel();
            Object.DontDestroyOnLoad(drawer);
        }

19 Source : GUIDrawer.cs
with GNU General Public License v3.0
from aelariane

public void Enable(int currentDepth)
        {
            if (drawer != null)
            {
                return;
            }
            drawer = new GameObject(owner.Name + "_DrawerObject").AddComponent<GUIDrawerObject>();
            drawer.layer = currentDepth;
            drawer.owner = this;
            drawer.Cancel();
            Object.DontDestroyOnLoad(drawer);
        }

19 Source : Style.cs
with GNU General Public License v3.0
from aelariane

private static void InitializeStyles()
        {
            Textures.Initialize();
            Color[] textColorsArray = new Color[6] { TextColors[0].HexToColor(), TextColors[1].HexToColor(), TextColors[2].HexToColor(), TextColors[3].HexToColor(), TextColors[4].HexToColor(), TextColors[5].HexToColor() };
            //Box
            Box.ApplyStyle(TextAnchor.UpperCenter, FontStyle.Bold, FontSize + 2, true, textColorsArray[0]);
            Box.name = "aBox";
            Box.richText = true;
            Box.normal.background = Textures.TextureCache[ElementType.Box][0];
            Box.hover.background = Textures.TextureCache[ElementType.Box][0];
            Box.active.background = Textures.TextureCache[ElementType.Box][0];
            //Button
            Button.ApplyStyle(TextAnchor.MiddleCenter, FontStyle.Normal, FontSize, true, textColorsArray);
            Button.name = "aButton";
            Button.richText = true;
            Button.normal.background = Textures.TextureCache[ElementType.Button][0];
            Button.hover.background = Textures.TextureCache[ElementType.Button][1];
            Button.active.background = Textures.TextureCache[ElementType.Button][2];
            //Label
            Label.ApplyStyle(TextAnchor.MiddleLeft, FontStyle.Normal, FontSize, true, textColorsArray);
            Label.name = "aLabel";
            Label.richText = true;
            LabelCenter.name = "aLabelCenter";
            LabelCenter.ApplyStyle(TextAnchor.MiddleCenter, FontStyle.Normal, FontSize, true, textColorsArray);
            LabelCenter.richText = true;
            //SelectionGrid
            SelectionGrid.ApplyStyle(TextAnchor.MiddleCenter, FontStyle.Normal, FontSize, false, textColorsArray);
            SelectionGrid.name = "aGrid";
            SelectionGrid.richText = true;
            SelectionGrid.normal.background = Textures.TextureCache[ElementType.SelectionGrid][0];
            SelectionGrid.hover.background = Textures.TextureCache[ElementType.SelectionGrid][1];
            SelectionGrid.active.background = Textures.TextureCache[ElementType.SelectionGrid][2];
            SelectionGrid.onNormal.background = Textures.TextureCache[ElementType.SelectionGrid][3];
            SelectionGrid.onHover.background = Textures.TextureCache[ElementType.SelectionGrid][4];
            SelectionGrid.onActive.background = Textures.TextureCache[ElementType.SelectionGrid][5];
            //Slider
            Slider.name = "aSlider";
            Slider.normal.background = Textures.TextureCache[ElementType.Slider][0];
            Slider.hover.background = Textures.TextureCache[ElementType.Slider][1];
            Slider.active.background = Textures.TextureCache[ElementType.Slider][2];
            Slider.onNormal.background = Textures.TextureCache[ElementType.Slider][3];
            Slider.onHover.background = Textures.TextureCache[ElementType.Slider][4];
            Slider.onActive.background = Textures.TextureCache[ElementType.Slider][5];
            //SliderBody
            SliderBody.name = "aSliderBody";
            SliderBody.normal.background = Textures.TextureCache[ElementType.SliderBody][0];
            SliderBody.hover.background = Textures.TextureCache[ElementType.SliderBody][1];
            SliderBody.active.background = Textures.TextureCache[ElementType.SliderBody][2];
            SliderBody.onNormal.background = Textures.TextureCache[ElementType.SliderBody][3];
            SliderBody.onHover.background = Textures.TextureCache[ElementType.SliderBody][4];
            SliderBody.onActive.background = Textures.TextureCache[ElementType.SliderBody][5];
            SliderBody.fixedWidth = Height;
            SliderBody.fixedHeight = Height;
            //TextField
            TextField.name = "aTextfield";
            TextField.ApplyStyle(TextAnchor.MiddleLeft, FontStyle.Normal, FontSize, false, textColorsArray);
            TextField.richText = false;
            TextField.clipping = TextClipping.Clip;
            TextField.normal.background = Textures.TextureCache[ElementType.TextField][0];
            TextField.hover.background = Textures.TextureCache[ElementType.TextField][1];
            TextField.active.background = Textures.TextureCache[ElementType.TextField][2];
            //Toggle
            Toggle.name = "aToggle";
            Toggle.normal.background = Textures.TextureCache[ElementType.Toggle][0];
            Toggle.hover.background = Textures.TextureCache[ElementType.Toggle][1];
            Toggle.active.background = Textures.TextureCache[ElementType.Toggle][2];
            Toggle.onNormal.background = Textures.TextureCache[ElementType.Toggle][3];
            Toggle.onHover.background = Textures.TextureCache[ElementType.Toggle][4];
            Toggle.onActive.background = Textures.TextureCache[ElementType.Toggle][5];
            //ToggleButton
            TextButton.name = "aTextButton";
            TextButton.ApplyStyle(TextAnchor.MiddleRight, FontStyle.Normal, FontSize, true, new Color[6] { white, orange, yellow, white, white, white });
            TextButton.richText = true;
            TextButton.normal.background = GUIBase.EmptyTexture;
            TextButton.normal = TextButton.hover = TextButton.active;
            SetFont(Font);

            //var upBtn = new GUIStyle(GUIStyle.none);
            //upBtn.name = "upbutton";
            //var downBtn = new GUIStyle(GUIStyle.none);
            //downBtn.name = "downbutton";
            //var thumb = new GUIStyle();
            //var arr = Textures.Test();
            //thumb.margin = new RectOffset(1, 1, 1, 1);
            //thumb.normal.background = arr[0];
            //thumb.hover.background = arr[1];
            //thumb.active.background = arr[2];
            //thumb.focused.background = arr[2];
            //thumb.onNormal.background = arr[0];
            //thumb.onHover.background = arr[1];
            //thumb.onActive.background = arr[2];
            //thumb.onFocused.background = arr[2];
            //thumb.name = "thumb";
            //thumb.fixedHeight = 20f;
            //thumb.fixedWidth = 20f;

            CustomStyles = new GUIStyle[]
            {
                Box, Button, Label, LabelCenter,
                SelectionGrid, Slider, SliderBody,
                TextField, Toggle, TextButton,
                //upBtn, downBtn, thumb
            };

            new GameObject("UISetter").AddComponent<StyleInitializer>();
        }

19 Source : AnarchyManager.cs
with GNU General Public License v3.0
from aelariane

private void Awake()
        {
            StartCoroutine(OnGameWasOpened());
            DontDestroyOnLoad(this);
            Feed = new GameFeed();
            Background = new Background();
            MainMenu = new UI.PanelMain();
            Pause = new PausePanel();
            PauseWindow = new PauseWindow();
            ProfilePanel = new ProfilePanel();
            SinglePanel = new SinglePanel();
            ServerList = new ServerListPanel();
            SettingsPanel = new SettingsPanel();
            DebugPanel = new DebugPanel();
            CharacterSelectionPanel = new CharacterSelectionPanel();
            Chat = new Chat();
            Log = new Log();
            ChatHistory = new ChatHistoryPanel();
            StatsPanel = new SingleStatsPanel();
            DontDestroyOnLoad(new GameObject("DiscordManager").AddComponent<Network.Discord.DiscordSDK>());
            DestroyMainScene();
            GameModes.ResetOnLoad();
            //Antis.Spam.EventsCounter.OnEventsSpamDetected += (sender, args) =>
            //{
            //    if (args.SpammedObject == 200 || args.SpammedObject == 253 && args.Count < 130)
            //    {
            //        return;
            //    }
            //    PhotonPlayer player = PhotonPlayer.Find(args.Sender);
            //    if (player.RCIgnored)
            //    {
            //        return;
            //    }
            //    Log.AddLine("eventSpam", args.SpammedObject.ToString(), args.Sender.ToString(), args.Count.ToString());
            //};
            //Antis.Spam.RPCCounter.OnRPCSpamDetected += (sender, args) =>
            //{
            //    if (args.SpammedObject == "netPauseAnimation" || args.SpammedObject == "netCrossFade" && args.Count < 75)
            //    {
            //        return;
            //    }
            //    PhotonPlayer player = PhotonPlayer.Find(args.Sender);
            //    if (player.RCIgnored)
            //    {
            //        return;
            //    }
            //    Log.AddLine("rpcSpam", args.SpammedObject.ToString(), args.Sender.ToString(), args.Count.ToString());
            //};
            //Antis.Spam.InstantiateCounter.OnInstantiateSpamDetected += (sender, args) =>
            //{
            //    if (args.SpammedObject.Contains("replacedAN") && args.Count <= 50)
            //    {
            //        return;
            //    }
            //    PhotonPlayer player = PhotonPlayer.Find(args.Sender);
            //    if (player.RCIgnored)
            //    {
            //        return;
            //    }
            //    Log.AddLine("instantiateSpam", args.SpammedObject.ToString(), args.Sender.ToString(), args.Count.ToString());
            //};
            //Antis.AntisManager.ResponseAction += (id, ban, reason) =>
            //{
            //    var player = PhotonPlayer.Find(id);
            //    if(player == null)
            //    {
            //        return;
            //    }
            //    Network.Antis.Kick(player, ban, reason);
            //};
            Network.BanList.Load();
            Antis.AntisManager.ResponseAction += (a, b, c) => { Network.Antis.Kick(PhotonPlayer.Find(a), b, c); };
            Antis.AntisManager.OnResponseCallback += (id, banned, reason) =>
            {
                Log.AddLineRaw($"Player [{id}] has been {(banned ? "banned" : "kicked")}. " +
                                  $"{(reason == "" ? "" : $"reason: {reason}")}");
            };
        }

19 Source : ClothFactory.cs
with GNU General Public License v3.0
from aelariane

public static GameObject GetCape(GameObject reference, string name, Material material)
    {
        List<GameObject> list;
        bool flag = ClothFactory.clothCache.TryGetValue(name, out list);
        GameObject result;
        if (flag)
        {
            for (int i = 0; i < list.Count; i++)
            {
                GameObject gameObject = list[i];
                bool flag2 = gameObject == null;
                if (flag2)
                {
                    list.RemoveAt(i);
                    i = Mathf.Max(i - 1, 0);
                }
                else
                {
                    ParentFollow component = gameObject.GetComponent<ParentFollow>();
                    bool flag3 = !component.isActiveInScene;
                    if (flag3)
                    {
                        component.isActiveInScene = true;
                        gameObject.renderer.material = material;
                        gameObject.GetComponent<Cloth>().enabled = true;
                        gameObject.GetComponent<SkinnedMeshRenderer>().enabled = true;
                        gameObject.GetComponent<ParentFollow>().SetParent(reference.transform);
                        ClothFactory.ReapplyClothBones(reference, gameObject);
                        return gameObject;
                    }
                }
            }
            GameObject gameObject2 = ClothFactory.GenerateCloth(reference, name);
            gameObject2.renderer.material = material;
            gameObject2.AddComponent<ParentFollow>().SetParent(reference.transform);
            list.Add(gameObject2);
            ClothFactory.clothCache[name] = list;
            result = gameObject2;
        }
        else
        {
            GameObject gameObject2 = ClothFactory.GenerateCloth(reference, name);
            gameObject2.renderer.material = material;
            gameObject2.AddComponent<ParentFollow>().SetParent(reference.transform);
            list = new List<GameObject>
            {
                gameObject2
            };
            ClothFactory.clothCache.Add(name, list);
            result = gameObject2;
        }
        return result;
    }

19 Source : HERO_SETUP.cs
with GNU General Public License v3.0
from aelariane

private GameObject GenerateCloth(GameObject go, string res)
    {
        if (!go.GetComponent<SkinnedMeshRenderer>())
        {
            go.AddComponent<SkinnedMeshRenderer>();
        }
        SkinnedMeshRenderer component = go.GetComponent<SkinnedMeshRenderer>();
        Transform[] bones = component.bones;
        SkinnedMeshRenderer component2 = ((GameObject)UnityEngine.Object.Instantiate(CacheResources.Load(res))).GetComponent<SkinnedMeshRenderer>();
        component2.gameObject.transform.parent = component.gameObject.transform.parent;
        component2.transform.localPosition = Vectors.zero;
        component2.transform.localScale = Vectors.one;
        component2.bones = bones;
        component2.quality = SkinQuality.Auto;
        return component2.gameObject;
    }

19 Source : ClothFactory.cs
with GNU General Public License v3.0
from aelariane

private static GameObject GenerateCloth(GameObject go, string res)
    {
        bool flag = go.GetComponent<SkinnedMeshRenderer>() == null;
        if (flag)
        {
            go.AddComponent<SkinnedMeshRenderer>();
        }
        Transform[] bones = go.GetComponent<SkinnedMeshRenderer>().bones;
        SkinnedMeshRenderer component = ((GameObject)UnityEngine.Object.Instantiate(Resources.Load(res))).GetComponent<SkinnedMeshRenderer>();
        component.transform.localScale = Vector3.one;
        component.bones = bones;
        component.quality = SkinQuality.Bone4;
        return component.gameObject;
    }

19 Source : ClothFactory.cs
with GNU General Public License v3.0
from aelariane

public static GameObject GetHair(GameObject reference, string name, Material material, Color color)
    {
        List<GameObject> list;
        bool flag = ClothFactory.clothCache.TryGetValue(name, out list);
        GameObject result;
        if (flag)
        {
            for (int i = 0; i < list.Count; i++)
            {
                GameObject gameObject = list[i];
                bool flag2 = gameObject == null;
                if (flag2)
                {
                    Debug.Log("Hair is null");
                    list.RemoveAt(i);
                    i = Mathf.Max(i - 1, 0);
                }
                else
                {
                    ParentFollow component = gameObject.GetComponent<ParentFollow>();
                    bool flag3 = !component.isActiveInScene;
                    if (flag3)
                    {
                        component.isActiveInScene = true;
                        gameObject.renderer.material = material;
                        gameObject.renderer.material.color = color;
                        gameObject.GetComponent<Cloth>().enabled = true;
                        gameObject.GetComponent<SkinnedMeshRenderer>().enabled = true;
                        gameObject.GetComponent<ParentFollow>().SetParent(reference.transform);
                        ClothFactory.ReapplyClothBones(reference, gameObject);
                        return gameObject;
                    }
                }
            }
            GameObject gameObject2 = ClothFactory.GenerateCloth(reference, name);
            gameObject2.renderer.material = material;
            gameObject2.renderer.material.color = color;
            gameObject2.AddComponent<ParentFollow>().SetParent(reference.transform);
            list.Add(gameObject2);
            ClothFactory.clothCache[name] = list;
            result = gameObject2;
        }
        else
        {
            GameObject gameObject2 = ClothFactory.GenerateCloth(reference, name);
            gameObject2.renderer.material = material;
            gameObject2.renderer.material.color = color;
            gameObject2.AddComponent<ParentFollow>().SetParent(reference.transform);
            list = new List<GameObject>
            {
                gameObject2
            };
            ClothFactory.clothCache.Add(name, list);
            result = gameObject2;
        }
        return result;
    }

19 Source : COLOSSAL_TITAN.cs
with GNU General Public License v3.0
from aelariane

[RPC]
    public void labelRPC(int health, int maxHealth)
    {
        if (health < 0)
        {
            if (healthLabel != null)
            {
                Destroy(this.healthLabel);
            }
        }
        else
        {
            if (healthLabel == null)
            {
                healthLabel = (GameObject)Instantiate(CacheResources.Load("UI/LabelNameOverHead"));
                healthLabel.name = "LabelNameOverHead";
                healthLabel.transform.parent = transform;
                healthLabel.transform.localPosition = new Vector3(0f, 430f, 0f);
                float num = 15f;
                if (this.size > 0f && this.size < 1f)
                {
                    num = 15f / this.size;
                    num = Mathf.Min(num, 100f);
                }
                this.healthLabel.transform.localScale = new Vector3(num, num, num);
                healthLabel.GetComponent<UILabel>().text = string.Empty;
                TextMesh txt = healthLabel.GetComponent<TextMesh>();
                if (txt == null)
                {
                    txt = healthLabel.AddComponent<TextMesh>();
                }
                MeshRenderer render = healthLabel.GetComponent<MeshRenderer>();
                if (render == null)
                {
                    render = healthLabel.AddComponent<MeshRenderer>();
                }
                render.material = Optimization.Labels.Font.material;
                txt.font = Optimization.Labels.Font;
                txt.fontSize = 20;
                txt.anchor = TextAnchor.MiddleCenter;
                txt.alignment = TextAlignment.Center;
                txt.color = Colors.white;
                txt.text = healthLabel.GetComponent<UILabel>().text;
                txt.richText = true;
                txt.gameObject.layer = 5;
            }
            string str = "[7FFF00]";
            float num2 = (float)health / (float)maxHealth;
            if (num2 < 0.75f && num2 >= 0.5f)
            {
                str = "[f2b50f]";
            }
            else if (num2 < 0.5f && num2 >= 0.25f)
            {
                str = "[ff8100]";
            }
            else if (num2 < 0.25f)
            {
                str = "[ff3333]";
            }
            this.healthLabel.GetComponent<TextMesh>().text = (str + System.Convert.ToString(health)).ToHTMLFormat();
        }
    }

19 Source : IN_GAME_MAIN_CAMERA.cs
with GNU General Public License v3.0
from aelariane

private void CreateMinimap()
    {
        LevelInfo info = FengGameManagerMKII.Level;
        if (info != null)
        {
            Minimap minimap = base.gameObject.AddComponent<Minimap>();
            if (Minimap.instance.myCam == null)
            {
                Minimap.instance.myCam = new GameObject().AddComponent<Camera>();
                Minimap.instance.myCam.nearClipPlane = 0.3f;
                Minimap.instance.myCam.farClipPlane = 1000f;
                Minimap.instance.myCam.enabled = false;
            }
            minimap.CreateMinimap(Minimap.instance.myCam, 512, 0.3f, info.minimapPreset);
            if (!Settings.Minimap.Value || GameModes.MinimapDisable.Enabled)
            {
                minimap.SetEnabled(false);
            }
        }
    }

19 Source : FengPhotonCalls.cs
with GNU General Public License v3.0
from aelariane

private void OnLevelWasLoaded(int level)
    {
        if (level == 0)
        {
            return;
        }

        if (Application.loadedLevelName == "characterCreation" || Application.loadedLevelName == "SnapShot")
        {
            return;
        }

        var array = GameObject.FindGameObjectsWithTag("replacedan");
        foreach (var go in array)
        {
            if (go.GetPhotonView() == null || !go.GetPhotonView().owner.IsMasterClient)
            {
                Destroy(go);
            }
        }

        gameStart = true;
        Pool.Clear();
        Anarchy.Skins.SkinElement.ClearCache();
        RespawnPositions.Dispose();
        ShowHUDInfoCenter(string.Empty);
        var gameObject2 = (GameObject)Instantiate(CacheResources.Load("MainCamera_mono"),
            CacheGameObject.Find("cameraDefaultPosition").transform.position,
            CacheGameObject.Find("cameraDefaultPosition").transform.rotation);
        Destroy(CacheGameObject.Find("cameraDefaultPosition"));
        gameObject2.name = "MainCamera";
        Screen.lockCursor = true;
        Screen.showCursor = true;
        var ui = (GameObject)Instantiate(CacheResources.Load("UI_IN_GAME"));
        ui.name = "UI_IN_GAME";
        ui.SetActive(true);
        UIRefer = ui.GetComponent<UIReferArray>();
        NGUITools.SetActive(UIRefer.panels[0], true);
        NGUITools.SetActive(UIRefer.panels[1], false);
        NGUITools.SetActive(UIRefer.panels[2], false);
        NGUITools.SetActive(UIRefer.panels[3], false);
        IN_GAME_MAIN_CAMERA.MainCamera.setHUDposition();
        IN_GAME_MAIN_CAMERA.MainCamera.setDayLight(IN_GAME_MAIN_CAMERA.DayLight);
        var info = Level;
        ClothFactory.ClearClothCache();
        logic.OnGameRestart();
        PlayerList = new PlayerList();
        if (IN_GAME_MAIN_CAMERA.GameType == GameType.Single)
        {
            LoadSkinCheck();
            CustomLevel.OnLoadLevel();
            singleKills = 0;
            singleMax = 0;
            singleTotal = 0;
            IN_GAME_MAIN_CAMERA.MainCamera.enabled = true;
            IN_GAME_MAIN_CAMERA.SpecMov.disable = true;
            IN_GAME_MAIN_CAMERA.Look.disable = true;
            IN_GAME_MAIN_CAMERA.GameMode = Level.Mode;
            SpawnPlayer(IN_GAME_MAIN_CAMERA.singleCharacter.ToUpper());
            Screen.lockCursor = IN_GAME_MAIN_CAMERA.CameraMode >= CameraType.TPS;
            Screen.showCursor = false;
            var rate = 90;
            if (difficulty == 1)
            {
                rate = 70;
            }

            SpawnreplacedansCustom(rate, info.EnemyNumber);
            return;
        }

        PVPcheckPoint.chkPts = new ArrayList();
        IN_GAME_MAIN_CAMERA.MainCamera.enabled = false;
        IN_GAME_MAIN_CAMERA.BaseCamera.GetComponent<CameraShake>().enabled = false;
        IN_GAME_MAIN_CAMERA.GameType = GameType.MultiPlayer;
        LoadSkinCheck();
        CustomLevel.OnLoadLevel();
        switch (info.Mode)
        {
            case GameMode.Trost:
                {
                    CacheGameObject.Find("playerRespawn").SetActive(false);
                    Destroy(CacheGameObject.Find("playerRespawn"));
                    var gameObject3 = CacheGameObject.Find("rock");
                    gameObject3.animation["lift"].speed = 0f;
                    CacheGameObject.Find("door_fine").SetActive(false);
                    CacheGameObject.Find("door_broke").SetActive(true);
                    Destroy(CacheGameObject.Find("ppl"));
                    break;
                }
            case GameMode.BossFightCT:
                CacheGameObject.Find("playerRespawnTrost").SetActive(false);
                Destroy(CacheGameObject.Find("playerRespawnTrost"));
                break;
        }

        if (needChooseSide)
        {
            ShowHUDInfoTopCenterADD("\n\nPRESS 1 TO ENTER GAME");
        }
        else
        {
            Screen.lockCursor = IN_GAME_MAIN_CAMERA.CameraMode >= CameraType.TPS;
            if (IN_GAME_MAIN_CAMERA.GameMode == GameMode.PVP_CAPTURE)
            {
                if ((int)PhotonNetwork.player.Properties[PhotonPlayerProperty.isreplacedan] == 2)
                {
                    checkpoint = CacheGameObject.Find("PVPchkPtT");
                }
                else
                {
                    checkpoint = CacheGameObject.Find("PVPchkPtH");
                }
            }

            if ((int)PhotonNetwork.player.Properties[PhotonPlayerProperty.isreplacedan] == 2)
            {
                SpawnNonAireplacedan(myLastHero);
            }
            else
            {
                SpawnPlayer(myLastHero);
            }
        }

        if (info.Mode == GameMode.BossFightCT)
        {
            Destroy(CacheGameObject.Find("rock"));
        }

        if (PhotonNetwork.IsMasterClient)
        {
            switch (info.Mode)
            {
                case GameMode.Trost:
                    {
                        if (!IsPlayerAllDead())
                        {
                            var gameObject4 = Pool.NetworkEnable("replacedAN_EREN_trost", new Vector3(-200f, 0f, -194f),
                                Quaternion.Euler(0f, 180f, 0f));
                            gameObject4.GetComponent<replacedAN_EREN>().rockLift = true;
                            var rate2 = 90;
                            if (difficulty == 1)
                            {
                                rate2 = 70;
                            }

                            var array3 = GameObject.FindGameObjectsWithTag("replacedanRespawn");
                            var gameObject5 = CacheGameObject.Find("replacedanRespawnTrost");
                            if (gameObject5 != null)
                            {
                                foreach (var gameObject6 in array3)
                                {
                                    if (gameObject6.transform.parent.gameObject == gameObject5)
                                    {
                                        Spawnreplacedan(rate2, gameObject6.transform.position, gameObject6.transform.rotation);
                                    }
                                }
                            }
                        }

                        break;
                    }
                case GameMode.BossFightCT:
                    {
                        if (!IsPlayerAllDead())
                        {
                            Pool.NetworkEnable("COLOSSAL_replacedAN", -Vectors.up * 10000f, Quaternion.Euler(0f, 180f, 0f));
                        }

                        break;
                    }
                case GameMode.Killreplacedan:
                case GameMode.Endlessreplacedan:
                case GameMode.SurviveMode:
                    {
                        if (info.Name == "Annie" || info.Name == "Annie II")
                        {
                            Pool.NetworkEnable("FEMALE_replacedAN", CacheGameObject.Find("replacedanRespawn").transform.position,
                                CacheGameObject.Find("replacedanRespawn").transform.rotation);
                        }
                        else
                        {
                            var rate3 = 90;
                            if (difficulty == 1)
                            {
                                rate3 = 70;
                            }

                            SpawnreplacedansCustom(rate3, info.EnemyNumber);
                        }

                        break;
                    }
                default:
                    {
                        if (info.Mode != GameMode.Trost)
                        {
                            if (info.Mode == GameMode.PVP_CAPTURE && Level.MapName == "OutSide")
                            {
                                var array5 = GameObject.FindGameObjectsWithTag("replacedanRespawn");
                                if (array5.Length <= 0)
                                {
                                    return;
                                }

                                for (var k = 0; k < array5.Length; k++)
                                {
                                    SpawnreplacedanRaw(array5[k].transform.position, array5[k].transform.rotation)
                                        .SetAbnormalType(AbnormalType.Crawler, true);
                                }
                            }
                        }

                        break;
                    }
            }
        }

        if (!info.Supply)
        {
            Destroy(CacheGameObject.Find("aot_supply"));
        }

        if (!PhotonNetwork.IsMasterClient)
        {
            BasePV.RPC("RequireStatus", PhotonTargets.MasterClient);
        }

        if (Stylish != null)
        {
            Stylish.enabled = true;
        }

        if (Level.LavaMode)
        {
            Instantiate(CacheResources.Load("levelBottom"), new Vector3(0f, -29.5f, 0f), Quaternion.Euler(0f, 0f, 0f));
            CacheGameObject.Find("aot_supply").transform.position =
                CacheGameObject.Find("aot_supply_lava_position").transform.position;
            CacheGameObject.Find("aot_supply").transform.rotation =
                CacheGameObject.Find("aot_supply_lava_position").transform.rotation;
        }

        if (GameModes.BombMode.Enabled)
        {
            if (Level.Name.StartsWith("The Forest"))
            {
                // Added the creation of an empty gameobject with MapCeilingObject as a component - Thyme 02/28/21
                GameObject mapCeiling = new GameObject("MapCeilingPrefab");
                mapCeiling.AddComponent<TLW.MapCeiling>();
                mapCeiling.transform.position = new Vector3(0f, 280f, 0f);
                mapCeiling.transform.rotation = Quaternion.idenreplacedy;
                mapCeiling.transform.localScale = new Vector3(1320f, 20f, 1320f);
            }
            else if (Level.Name.StartsWith("The City"))
            {
                GameObject mapCeiling = new GameObject("MapCeilingPrefab");
                mapCeiling.AddComponent<TLW.MapCeiling>();
                mapCeiling.transform.position = new Vector3(0f, 210f, 0f);
                mapCeiling.transform.rotation = Quaternion.idenreplacedy;
                mapCeiling.transform.localScale = new Vector3(1400f, 20f, 1400f);
            }
        }

        roomInformation.UpdateLabels();
        Resources.UnloadUnusedreplacedets();
    }

19 Source : UIMainReferences.cs
with GNU General Public License v3.0
from aelariane

private void Start()
    {
        GameObject.Find("VERSION").GetComponent<UILabel>().text = "Loading...";
        NGUITools.SetActive(this.panelMain, false);
        if (isGAMEFirstLaunch)
        {
            isGAMEFirstLaunch = false;
            GameObject input = (GameObject)Resources.Load("InputManagerController");
            input.GetComponent<FengCustomInputs>().enabled = false;
            input.AddComponent<Anarchy.InputManager>();
            var inputs = (GameObject)Instantiate(input);
            inputs.name = "InputManagerController";
            DontDestroyOnLoad(inputs);
            new GameObject("AnarchyManager").AddComponent<Anarchy.AnarchyManager>();
        }
        Anarchy.Network.NetworkManager.TryRejoin();
    }

19 Source : AnarchyManager.cs
with GNU General Public License v3.0
from aelariane

private IEnumerator OnGameWasOpened()
        {
            var back = new GameObject("TempBackground").AddComponent<BackgroundOnStart>();
            yield return StartCoroutine(Anarchyreplacedets.LoadreplacedetBundle());
            Instantiate(Anarchyreplacedets.Load("UIManager"));
            Instantiate(Anarchyreplacedets.Load("LoadScreen"));
            Destroy(back);
        }

19 Source : UIDragCamera.cs
with GNU General Public License v3.0
from aelariane

private void Awake()
    {
        if (this.target != null)
        {
            if (this.draggableCamera == null)
            {
                this.draggableCamera = this.target.GetComponent<UIDraggableCamera>();
                if (this.draggableCamera == null)
                {
                    this.draggableCamera = this.target.gameObject.AddComponent<UIDraggableCamera>();
                }
            }
            this.target = null;
        }
        else if (this.draggableCamera == null)
        {
            this.draggableCamera = NGUITools.FindInParents<UIDraggableCamera>(base.gameObject);
        }
    }

19 Source : EquipItems.cs
with GNU General Public License v3.0
from aelariane

private void Start()
    {
        if (this.itemIDs != null && this.itemIDs.Length > 0)
        {
            InvEquipment invEquipment = base.GetComponent<InvEquipment>();
            if (invEquipment == null)
            {
                invEquipment = base.gameObject.AddComponent<InvEquipment>();
            }
            int max = 12;
            int i = 0;
            int num = this.itemIDs.Length;
            while (i < num)
            {
                int num2 = this.itemIDs[i];
                InvBaseItem invBaseItem = InvDatabase.FindByID(num2);
                if (invBaseItem != null)
                {
                    invEquipment.Equip(new InvGameItem(num2, invBaseItem)
                    {
                        quality = (InvGameItem.Quality)UnityEngine.Random.Range(0, max),
                        itemLevel = NGUITools.RandomRange(invBaseItem.minItemLevel, invBaseItem.maxItemLevel)
                    });
                }
                else
                {
                    Debug.LogWarning("Can't resolve the item ID of " + num2);
                }
                i++;
            }
        }
        UnityEngine.Object.Destroy(this);
    }

19 Source : ActiveAnimation.cs
with GNU General Public License v3.0
from aelariane

public static ActiveAnimation Play(Animation anim, string clipName, Direction playDirection, EnableCondition enableBeforePlay, DisableCondition disableCondition)
    {
        if (!NGUITools.GetActive(anim.gameObject))
        {
            if (enableBeforePlay != EnableCondition.EnableThenPlay)
            {
                return null;
            }
            NGUITools.SetActive(anim.gameObject, true);
            UIPanel[] componentsInChildren = anim.gameObject.GetComponentsInChildren<UIPanel>();
            int i = 0;
            int num = componentsInChildren.Length;
            while (i < num)
            {
                componentsInChildren[i].Refresh();
                i++;
            }
        }
        ActiveAnimation activeAnimation = anim.GetComponent<ActiveAnimation>();
        if (activeAnimation == null)
        {
            activeAnimation = anim.gameObject.AddComponent<ActiveAnimation>();
        }
        activeAnimation.mAnim = anim;
        activeAnimation.mDisableDirection = (Direction)disableCondition;
        activeAnimation.eventReceiver = null;
        activeAnimation.callWhenFinished = null;
        activeAnimation.onFinished = null;
        activeAnimation.Play(clipName, playDirection);
        return activeAnimation;
    }

19 Source : NGUIDebug.cs
with GNU General Public License v3.0
from aelariane

public static void Log(string text)
    {
        if (Application.isPlaying)
        {
            if (NGUIDebug.mLines.Count > 20)
            {
                NGUIDebug.mLines.RemoveAt(0);
            }
            NGUIDebug.mLines.Add(text);
            if (NGUIDebug.mInstance == null)
            {
                GameObject gameObject = new GameObject("_NGUI Debug");
                NGUIDebug.mInstance = gameObject.AddComponent<NGUIDebug>();
                UnityEngine.Object.DontDestroyOnLoad(gameObject);
            }
        }
        else
        {
            Debug.Log(text);
        }
    }

19 Source : SpringPanel.cs
with GNU General Public License v3.0
from aelariane

public static SpringPanel Begin(GameObject go, Vector3 pos, float strength)
    {
        SpringPanel springPanel = go.GetComponent<SpringPanel>();
        if (springPanel == null)
        {
            springPanel = go.AddComponent<SpringPanel>();
        }
        springPanel.target = pos;
        springPanel.strength = strength;
        springPanel.onFinished = null;
        if (!springPanel.enabled)
        {
            springPanel.mThreshold = 0f;
            springPanel.enabled = true;
        }
        return springPanel;
    }

19 Source : UIEventListener.cs
with GNU General Public License v3.0
from aelariane

public static UIEventListener Get(GameObject go)
    {
        UIEventListener uieventListener = go.GetComponent<UIEventListener>();
        if (uieventListener == null)
        {
            uieventListener = go.AddComponent<UIEventListener>();
        }
        return uieventListener;
    }

19 Source : UpdateManager.cs
with GNU General Public License v3.0
from aelariane

private static void CreateInstance()
    {
        if (UpdateManager.mInst == null)
        {
            UpdateManager.mInst = (UnityEngine.Object.FindObjectOfType(typeof(UpdateManager)) as UpdateManager);
            if (UpdateManager.mInst == null && Application.isPlaying)
            {
                GameObject gameObject = new GameObject("_UpdateManager");
                UnityEngine.Object.DontDestroyOnLoad(gameObject);
                UpdateManager.mInst = gameObject.AddComponent<UpdateManager>();
            }
        }
    }

19 Source : SpringPosition.cs
with GNU General Public License v3.0
from aelariane

public static SpringPosition Begin(GameObject go, Vector3 pos, float strength)
    {
        SpringPosition springPosition = go.GetComponent<SpringPosition>();
        if (springPosition == null)
        {
            springPosition = go.AddComponent<SpringPosition>();
        }
        springPosition.target = pos;
        springPosition.strength = strength;
        springPosition.onFinished = null;
        if (!springPosition.enabled)
        {
            springPosition.mThreshold = 0f;
            springPosition.enabled = true;
        }
        return springPosition;
    }

19 Source : UIDrawCall.cs
with GNU General Public License v3.0
from aelariane

public void Set(BetterList<Vector3> verts, BetterList<Vector3> norms, BetterList<Vector4> tans, BetterList<Vector2> uvs, BetterList<Color32> cols)
    {
        int size = verts.size;
        if (size > 0 && size == uvs.size && size == cols.size && size % 4 == 0)
        {
            if (this.mFilter == null)
            {
                this.mFilter = base.gameObject.GetComponent<MeshFilter>();
            }
            if (this.mFilter == null)
            {
                this.mFilter = base.gameObject.AddComponent<MeshFilter>();
            }
            if (this.mRen == null)
            {
                this.mRen = base.gameObject.GetComponent<MeshRenderer>();
            }
            if (this.mRen == null)
            {
                this.mRen = base.gameObject.AddComponent<MeshRenderer>();
                this.UpdateMaterials();
            }
            else if (this.mClippedMat != null && this.mClippedMat.mainTexture != this.mSharedMat.mainTexture)
            {
                this.UpdateMaterials();
            }
            if (verts.size < 65000)
            {
                int num = (size >> 1) * 3;
                bool flag = this.mIndices == null || this.mIndices.Length != num;
                if (flag)
                {
                    this.mIndices = new int[num];
                    int num2 = 0;
                    for (int i = 0; i < size; i += 4)
                    {
                        this.mIndices[num2++] = i;
                        this.mIndices[num2++] = i + 1;
                        this.mIndices[num2++] = i + 2;
                        this.mIndices[num2++] = i + 2;
                        this.mIndices[num2++] = i + 3;
                        this.mIndices[num2++] = i;
                    }
                }
                Mesh mesh = this.GetMesh(ref flag, verts.size);
                mesh.vertices = verts.ToArray();
                if (norms != null)
                {
                    mesh.normals = norms.ToArray();
                }
                if (tans != null)
                {
                    mesh.tangents = tans.ToArray();
                }
                mesh.uv = uvs.ToArray();
                mesh.colors32 = cols.ToArray();
                if (flag)
                {
                    mesh.triangles = this.mIndices;
                }
                mesh.RecalculateBounds();
                this.mFilter.mesh = mesh;
            }
            else
            {
                if (this.mFilter.mesh != null)
                {
                    this.mFilter.mesh.Clear();
                }
                Debug.LogError("Too many vertices on one panel: " + verts.size);
            }
        }
        else
        {
            if (this.mFilter.mesh != null)
            {
                this.mFilter.mesh.Clear();
            }
            Debug.LogError("UIWidgets must fill the buffer with 4 vertices per quad. Found " + size);
        }
    }

19 Source : UIPanel.cs
with GNU General Public License v3.0
from aelariane

private UIDrawCall GetDrawCall(Material mat, bool createIfMissing)
    {
        int i = 0;
        int size = this.drawCalls.size;
        while (i < size)
        {
            UIDrawCall uidrawCall = this.drawCalls.buffer[i];
            if (uidrawCall.material == mat)
            {
                return uidrawCall;
            }
            i++;
        }
        UIDrawCall uidrawCall2 = null;
        if (createIfMissing)
        {
            GameObject gameObject = new GameObject("_UIDrawCall [" + mat.name + "]");
            UnityEngine.Object.DontDestroyOnLoad(gameObject);
            gameObject.layer = this.cachedGameObject.layer;
            uidrawCall2 = gameObject.AddComponent<UIDrawCall>();
            uidrawCall2.material = mat;
            this.mDrawCalls.Add(uidrawCall2);
        }
        return uidrawCall2;
    }

19 Source : UIPanel.cs
with GNU General Public License v3.0
from aelariane

public static UIPanel Find(Transform trans, bool createIfMissing)
    {
        Transform y = trans;
        UIPanel uipanel = null;
        while (uipanel == null && trans != null)
        {
            uipanel = trans.GetComponent<UIPanel>();
            if (uipanel != null)
            {
                break;
            }
            if (trans.parent == null)
            {
                break;
            }
            trans = trans.parent;
        }
        if (createIfMissing && uipanel == null && trans != y)
        {
            uipanel = trans.gameObject.AddComponent<UIPanel>();
            UIPanel.SetChildLayer(uipanel.cachedTransform, uipanel.cachedGameObject.layer);
        }
        return uipanel;
    }

19 Source : XWeaponTrail.cs
with GNU General Public License v3.0
from aelariane

private void InitMeshObj()
        {
            mMeshObj = new GameObject("_XWeaponTrailMesh: " + gameObject.name);
            mMeshObj.layer = gameObject.layer;
            mMeshObj.SetActive(true);
            var filter = mMeshObj.AddComponent<MeshFilter>();
            var renderer = mMeshObj.AddComponent<MeshRenderer>();
            renderer.castShadows = false;
            renderer.receiveShadows = false;
            renderer.renderer.sharedMaterial = MyMaterial;
            filter.sharedMesh = new Mesh();
            mVertexPool = new VertexPool(filter.sharedMesh, MyMaterial);
            mVertexSegment = mVertexPool.GetVertices(Granularity * 3, (Granularity - 1) * 12);
            UpdateIndices();
        }

19 Source : NGUITools.cs
with GNU General Public License v3.0
from aelariane

public static T AddChild<T>(GameObject parent) where T : Component
    {
        GameObject gameObject = NGUITools.AddChild(parent);
        gameObject.name = NGUITools.GetName<T>();
        return gameObject.AddComponent<T>();
    }

19 Source : NGUITools.cs
with GNU General Public License v3.0
from aelariane

public static AudioSource PlaySound(AudioClip clip, float volume, float pitch)
    {
        volume *= NGUITools.soundVolume;
        if (clip != null && volume > 0.01f)
        {
            if (NGUITools.mListener == null)
            {
                NGUITools.mListener = (UnityEngine.Object.FindObjectOfType(typeof(AudioListener)) as AudioListener);
                if (NGUITools.mListener == null)
                {
                    Camera camera = IN_GAME_MAIN_CAMERA.BaseCamera;
                    if (camera == null)
                    {
                        camera = (UnityEngine.Object.FindObjectOfType(typeof(Camera)) as Camera);
                    }
                    if (camera != null)
                    {
                        NGUITools.mListener = camera.gameObject.AddComponent<AudioListener>();
                    }
                }
            }
            if (NGUITools.mListener != null && NGUITools.mListener.enabled && NGUITools.GetActive(NGUITools.mListener.gameObject))
            {
                AudioSource audioSource = NGUITools.mListener.audio;
                if (audioSource == null)
                {
                    audioSource = NGUITools.mListener.gameObject.AddComponent<AudioSource>();
                }
                audioSource.pitch = pitch;
                audioSource.PlayOneShot(clip, volume);
                return audioSource;
            }
        }
        return null;
    }

19 Source : UITweener.cs
with GNU General Public License v3.0
from aelariane

public static T Begin<T>(GameObject go, float duration) where T : UITweener
    {
        T t = go.GetComponent<T>();
        if (t == null)
        {
            t = go.AddComponent<T>();
        }
        t.mStarted = false;
        t.duration = duration;
        t.mFactor = 0f;
        t.mAmountPerDelta = Mathf.Abs(t.mAmountPerDelta);
        t.style = UITweener.Style.Once;
        t.animationCurve = new AnimationCurve(new Keyframe[]
        {
            new Keyframe(0f, 0f, 0f, 1f),
            new Keyframe(1f, 1f, 1f, 0f)
        });
        t.eventReceiver = null;
        t.callWhenFinished = null;
        t.onFinished = null;
        t.enabled = true;
        return t;
    }

19 Source : Labels.cs
with GNU General Public License v3.0
from aelariane

private static TextMesh CreateShadow(string name, int size, TextAnchor anchor, Color color, Font font, TextAlignment align, FontStyle style = FontStyle.Normal)
        {
            if (font == null)
            {
                return null;
            }

            GameObject res1 = GameObject.Find(name);
            if (res1 == null || res1.GetComponent<UILabel>() == null)
            {
                return null;
            }

            GameObject res = (GameObject)GameObject.Instantiate(res1, res1.transform.position, res1.transform.rotation);

            TextMesh text = res.GetComponent<TextMesh>();
            if (text == null)
            {
                text = res.AddComponent<TextMesh>();
            }

            MeshRenderer render = res.GetComponent<MeshRenderer>();
            if (render == null)
            {
                render = res.AddComponent<MeshRenderer>();
            }

            UILabel label = res.GetComponent<UILabel>();
            render.material = font.material;
            text.font = font;
            text.fontSize = Mathf.RoundToInt(size * Anarchy.UI.UIManager.LabelScale.Value);
            text.anchor = anchor;
            text.alignment = align;
            text.color = color;
            text.fontStyle = style;
            res.transform.SetParent(res1.transform.parent);
            res.transform.localPosition = res1.transform.localPosition;
            res.transform.localRotation = res1.transform.localRotation;
            res.transform.localScale = new Vector3(4.9f, 4.9f);
            Transform tf = text.transform;
            float deltaX = 1.25f;
            if (anchor == TextAnchor.MiddleRight || anchor == TextAnchor.UpperRight || anchor == TextAnchor.LowerRight)
            {
                deltaX = -deltaX;
            }
            float deltaY = 1.25f;
            if ((int)anchor >= 6)
            {
                deltaY = -deltaY;
            }

            deltaY *= Anarchy.UI.UIManager.LabelScale.Value;
            deltaX *= Anarchy.UI.UIManager.LabelScale.Value;
            tf.localPosition = new Vector3(tf.localPosition.x + deltaX, tf.localPosition.y - deltaY, tf.localPosition.z + 0.00001f);

            if (label != null)
            {
                text.text = label.text;
                label.enabled = false;
            }
            res.layer = 5;
            text.richText = true;
            text.gameObject.name = name + "(Shadow)";
            return text;
        }

19 Source : NGUITools.cs
with GNU General Public License v3.0
from aelariane

public static BoxCollider AddWidgetCollider(GameObject go)
    {
        if (go != null)
        {
            Collider component = go.GetComponent<Collider>();
            BoxCollider boxCollider = component as BoxCollider;
            if (boxCollider == null)
            {
                if (component != null)
                {
                    if (Application.isPlaying)
                    {
                        UnityEngine.Object.Destroy(component);
                    }
                    else
                    {
                        UnityEngine.Object.DestroyImmediate(component);
                    }
                }
                boxCollider = go.AddComponent<BoxCollider>();
            }
            int num = NGUITools.CalculateNextDepth(go);
            Bounds bounds = NGUIMath.CalculateRelativeWidgetBounds(go.transform);
            boxCollider.isTrigger = true;
            boxCollider.center = bounds.center + Vectors.back * ((float)num * 0.25f);
            boxCollider.size = new Vector3(bounds.size.x, bounds.size.y, 0f);
            return boxCollider;
        }
        return null;
    }

19 Source : PoolObject.cs
with GNU General Public License v3.0
from aelariane

private GameObject CreateObject(string name)
        {
            Object resource = name.StartsWith("RCreplacedet/") ? CacheResources.RCLoad(name) : CacheResources.Load(name);
            if (resource == null)
            {
                throw new System.Exception($"PoolObject.CreateObject(): Cannot find Resource with name \"{name}\". Please check Keys for values.");
            }
            GameObject res = (GameObject)Object.Instantiate(resource);
            res.AddComponent<PoolableObject>();
            //Object.DontDestroyOnLoad(res);
            res.SetActive(false);
            return res;
        }

19 Source : Labels.cs
with GNU General Public License v3.0
from aelariane

internal static TextMesh CreateLabel(string name, int size, TextAnchor anchor, Color color, Font font, TextAlignment align, FontStyle style = FontStyle.Normal)
        {
            if (font == null)
            {
                return null;
            }

            GameObject res = GameObject.Find(name);
            if (res == null || res.GetComponent<UILabel>() == null)
            {
                return null;
            }

            TextMesh text = res.GetComponent<TextMesh>();
            if (text == null)
            {
                text = res.AddComponent<TextMesh>();
            }

            MeshRenderer render = res.GetComponent<MeshRenderer>();
            if (render == null)
            {
                render = res.AddComponent<MeshRenderer>();
            }

            UILabel label = res.GetComponent<UILabel>();
            render.material = font.material;
            text.font = font;
            text.fontSize = Mathf.RoundToInt(size * Anarchy.UI.UIManager.LabelScale.Value);
            text.anchor = anchor;
            text.alignment = align;
            text.color = color;
            text.fontStyle = style;
            res.transform.SetParent(res.transform.parent);
            res.transform.localPosition = res.transform.localPosition;
            res.transform.localRotation = res.transform.localRotation;
            res.transform.localScale = new Vector3(4.9f, 4.9f);

            if (label != null)
            {
                text.text = label.text;
                label.enabled = false;
            }
            res.layer = 5;
            text.richText = true;
            return text;
        }

19 Source : ShowInfoOfPlayer.cs
with GNU General Public License v3.0
from aelariane

private void Start()
    {
        if (this.font == null)
        {
            this.font = (Font)Resources.FindObjectsOfTypeAll(typeof(Font))[0];
            Debug.LogWarning("No font defined. Found font: " + this.font);
        }
        if (this.tm == null)
        {
            this.textGo = new GameObject("3d text");
            this.textGo.transform.localScale = new Vector3(0.2f, 0.2f, 0.2f);
            this.textGo.transform.parent = base.gameObject.transform;
            this.textGo.transform.localPosition = Vectors.zero;
            MeshRenderer meshRenderer = this.textGo.AddComponent<MeshRenderer>();
            meshRenderer.material = this.font.material;
            this.tm = this.textGo.AddComponent<TextMesh>();
            this.tm.font = this.font;
            this.tm.fontSize = 0;
            this.tm.anchor = TextAnchor.MiddleCenter;
        }
        if (!this.DisableOnOwnObjects && BasePV.IsMine)
        {
            base.enabled = false;
        }
    }

19 Source : SupportLogger.cs
with GNU General Public License v3.0
from aelariane

public void Start()
    {
        GameObject gameObject = CacheGameObject.Find("PunSupportLogger");
        if (gameObject == null)
        {
            gameObject = new GameObject("PunSupportLogger");
            UnityEngine.Object.DontDestroyOnLoad(gameObject);
            SupportLogging supportLogging = gameObject.AddComponent<SupportLogging>();
            supportLogging.LogTrafficStats = this.LogTrafficStats;
        }
    }

19 Source : Minimap.cs
with GNU General Public License v3.0
from aelariane

private void CreateUnityUI(Texture2D map, int minimapResolution)
    {
        GameObject gameObject = new GameObject("Canvas");
        gameObject.AddComponent<RectTransform>();
        this.canvas = gameObject.AddComponent<Canvas>();
        this.canvas.renderMode = RenderMode.ScreenSpaceOverlay;
        this.scaler = gameObject.AddComponent<Canvreplacedcaler>();
        this.scaler.uiScaleMode = Canvreplacedcaler.ScaleMode.ScaleWithScreenSize;
        this.scaler.referenceResolution = new Vector2(900f, 600f);
        this.scaler.screenMatchMode = Canvreplacedcaler.ScreenMatchMode.MatchWidthOrHeight;
        GameObject gameObject2 = new GameObject("CircleMask");
        gameObject2.transform.SetParent(gameObject.transform, false);
        this.minimapMaskT = gameObject2.AddComponent<RectTransform>();
        gameObject2.AddComponent<CanvasRenderer>();
        RectTransform rectTransform = this.minimapMaskT;
        Vector2 vector = this.minimapMaskT.anchorMax = Vector2.one;
        rectTransform.anchorMin = vector;
        float num = this.MINIMAP_CORNER_SIZE * 0.5f;
        this.cornerPosition = new Vector2(-(num + 5f), -(num + 70f));
        this.minimapMaskT.ancreplaceddPosition = this.cornerPosition;
        this.minimapMaskT.sizeDelta = new Vector2(this.MINIMAP_CORNER_SIZE, this.MINIMAP_CORNER_SIZE);
        GameObject gameObject3 = new GameObject("Minimap");
        gameObject3.transform.SetParent(this.minimapMaskT, false);
        this.minimap = gameObject3.AddComponent<RectTransform>();
        gameObject3.AddComponent<CanvasRenderer>();
        RectTransform rectTransform2 = this.minimap;
        RectTransform rectTransform3 = this.minimap;
        vector = new Vector2(0.5f, 0.5f);
        rectTransform3.anchorMax = vector;
        rectTransform2.anchorMin = vector;
        this.minimap.ancreplaceddPosition = Vector2.zero;
        this.minimap.sizeDelta = this.minimapMaskT.sizeDelta;
        Image image = gameObject3.AddComponent<Image>();
        Rect rect = new Rect(0f, 0f, (float)map.width, (float)map.height);
        image.sprite = UnityEngine.Sprite.Create(map, rect, new Vector3(0.5f, 0.5f));
        image.type = Image.Type.Simple;
    }

19 Source : Minimap.cs
with GNU General Public License v3.0
from aelariane

private void CreateUnityUIRT(int minimapResolution)
    {
        GameObject gameObject = new GameObject("Canvas");
        gameObject.AddComponent<RectTransform>();
        this.canvas = gameObject.AddComponent<Canvas>();
        this.canvas.renderMode = RenderMode.ScreenSpaceOverlay;
        this.scaler = gameObject.AddComponent<Canvreplacedcaler>();
        this.scaler.uiScaleMode = Canvreplacedcaler.ScaleMode.ScaleWithScreenSize;
        this.scaler.referenceResolution = new Vector2(800f, 600f);
        this.scaler.screenMatchMode = Canvreplacedcaler.ScreenMatchMode.MatchWidthOrHeight;
        this.scaler.matchWidthOrHeight = 1f;
        GameObject gameObject2 = new GameObject("Mask");
        gameObject2.transform.SetParent(gameObject.transform, false);
        this.minimapMaskT = gameObject2.AddComponent<RectTransform>();
        gameObject2.AddComponent<CanvasRenderer>();
        RectTransform rectTransform = this.minimapMaskT;
        Vector2 vector = this.minimapMaskT.anchorMax = Vector2.one;
        rectTransform.anchorMin = vector;
        float num = this.MINIMAP_CORNER_SIZE * 0.5f;
        this.cornerPosition = new Vector2(-(num + 5f), -(num + 70f));
        this.minimapMaskT.ancreplaceddPosition = this.cornerPosition;
        this.minimapMaskT.sizeDelta = new Vector2(this.MINIMAP_CORNER_SIZE, this.MINIMAP_CORNER_SIZE);
        GameObject gameObject3 = new GameObject("MapBorder");
        gameObject3.transform.SetParent(this.minimapMaskT, false);
        this.borderT = gameObject3.AddComponent<RectTransform>();
        RectTransform rectTransform2 = this.borderT;
        RectTransform rectTransform3 = this.borderT;
        vector = new Vector2(0.5f, 0.5f);
        rectTransform3.anchorMax = vector;
        rectTransform2.anchorMin = vector;
        this.borderT.sizeDelta = this.minimapMaskT.sizeDelta;
        gameObject3.AddComponent<CanvasRenderer>();
        Image image = gameObject3.AddComponent<Image>();
        image.sprite = Minimap.borderSprite;
        image.type = Image.Type.Sliced;
        GameObject gameObject4 = new GameObject("Minimap");
        gameObject4.transform.SetParent(this.minimapMaskT, false);
        this.minimap = gameObject4.AddComponent<RectTransform>();
        this.minimap.SetAsFirstSibling();
        gameObject4.AddComponent<CanvasRenderer>();
        RectTransform rectTransform4 = this.minimap;
        RectTransform rectTransform5 = this.minimap;
        vector = new Vector2(0.5f, 0.5f);
        rectTransform5.anchorMax = vector;
        rectTransform4.anchorMin = vector;
        this.minimap.ancreplaceddPosition = Vector2.zero;
        this.minimap.sizeDelta = this.minimapMaskT.sizeDelta;
        RawImage rawImage = gameObject4.AddComponent<RawImage>();
        rawImage.texture = this.minimapRT;
        rawImage.maskable = true;
        gameObject4.AddComponent<Mask>().showMaskGraphic = true;
    }

19 Source : Minimap.cs
with GNU General Public License v3.0
from aelariane

public static Minimap.MinimapIcon Create(RectTransform parent, GameObject trackedObject, Minimap.IconStyle style)
        {
            UnityEngine.Sprite spriteForStyle = Minimap.GetSpriteForStyle(style);
            GameObject gameObject = new GameObject("MinimapIcon");
            RectTransform rectTransform = gameObject.AddComponent<RectTransform>();
            rectTransform.anchorMin = (rectTransform.anchorMax = new Vector3(0.5f, 0.5f));
            rectTransform.sizeDelta = new Vector2((float)spriteForStyle.texture.width, (float)spriteForStyle.texture.height);
            Image image = gameObject.AddComponent<Image>();
            image.sprite = spriteForStyle;
            image.type = Image.Type.Simple;
            gameObject.transform.SetParent(parent, false);
            return new Minimap.MinimapIcon(trackedObject, gameObject, style);
        }

19 Source : Minimap.cs
with GNU General Public License v3.0
from aelariane

public static Minimap.MinimapIcon CreateWithRotation(RectTransform parent, GameObject trackedObject, Minimap.IconStyle style, float pointerDist)
        {
            UnityEngine.Sprite spriteForStyle = Minimap.GetSpriteForStyle(style);
            GameObject gameObject = new GameObject("MinimapIcon");
            RectTransform rectTransform = gameObject.AddComponent<RectTransform>();
            rectTransform.anchorMin = (rectTransform.anchorMax = new Vector3(0.5f, 0.5f));
            rectTransform.sizeDelta = new Vector2((float)spriteForStyle.texture.width, (float)spriteForStyle.texture.height);
            Image image = gameObject.AddComponent<Image>();
            image.sprite = spriteForStyle;
            image.type = Image.Type.Simple;
            gameObject.transform.SetParent(parent, false);
            GameObject gameObject2 = new GameObject("IconPointer");
            RectTransform rectTransform2 = gameObject2.AddComponent<RectTransform>();
            rectTransform2.anchorMin = (rectTransform2.anchorMax = rectTransform.anchorMin);
            rectTransform2.sizeDelta = new Vector2((float)Minimap.pointerSprite.texture.width, (float)Minimap.pointerSprite.texture.height);
            Image image2 = gameObject2.AddComponent<Image>();
            image2.sprite = Minimap.pointerSprite;
            image2.type = Image.Type.Simple;
            gameObject2.transform.SetParent(rectTransform, false);
            rectTransform2.ancreplaceddPosition = new Vector2(0f, pointerDist);
            return new Minimap.MinimapIcon(trackedObject, gameObject, gameObject2, style);
        }

19 Source : NavToColliderCreater.cs
with MIT License
from akof1314

[MenuItem("Tool/NavToCollider Creater")]
    static void Init()
    {
        NavToCollider navToCollider = GameObject.FindObjectOfType<NavToCollider>();
        if (navToCollider == null)
        {
            GameObject go = GameObject.Find("[NavToColliderManager]");
            if (go)
            {
                navToCollider = Undo.AddComponent<NavToCollider>(go);
            }
            else
            {
                navToCollider = new GameObject("[NavToColliderManager]").AddComponent<NavToCollider>();
                Undo.RegisterCreatedObjectUndo(navToCollider.gameObject, "Create object");
            }
        }

        Selection.activeGameObject = navToCollider.gameObject;
        EditorGUIUtility.PingObject(navToCollider.gameObject);
    }

19 Source : NavToColliderEditor.cs
with MIT License
from akof1314

private void GenMeshCollider()
    {
        GameObject go = new GameObject("Mesh Collider");
        MeshCollider mc = go.AddComponent<MeshCollider>();
        go.transform.SetParent(m_NavToCollider.transform, false);
        Undo.RegisterCreatedObjectUndo(go, "GenMeshCollider");

        var ct = NavMesh.CalculateTriangulation();
        Mesh mesh = new Mesh();
        mesh.vertices = ct.vertices;
        mesh.triangles = ct.indices;
        mc.sharedMesh = mesh;
    }

19 Source : NavToColliderEditor.cs
with MIT License
from akof1314

private void GenBoxCollider(bool xAxis = false)
    {
        if (m_SelectedVerts.Count <= 1)
        {
            return;
        }

        Transform tf = m_NavToCollider.transform;
        GameObject go = new GameObject("Box Collider");
        go.transform.SetParent(tf, false);
        Undo.RegisterCreatedObjectUndo(go, "GenBoxCollider");

        List<Vector3> vertList = new List<Vector3>();
        foreach (var vertex in m_SelectedVerts)
        {
            vertList.Add(vertex);
        }

        Transform tf2 = go.transform;
        // 三点先构建一个平面
        if (vertList.Count >= 3)
        {
            Plane plane = new Plane(vertList[0], vertList[1], vertList[2]);
            Quaternion rotation = Quaternion.FromToRotation(tf2.up, -plane.normal) * tf2.rotation;
            tf2.rotation = rotation;
        }

        vertList.Clear();
        foreach (var vertex in m_SelectedVerts)
        {
            vertList.Add(tf2.InverseTransformPoint(vertex));
        }

        Vector3 min = new Vector3(Mathf.Infinity, Mathf.Infinity, Mathf.Infinity);
        Vector3 max = new Vector3(-Mathf.Infinity, -Mathf.Infinity, -Mathf.Infinity);
        foreach (var vertex in vertList)
        {
            min.x = Mathf.Min(vertex.x, min.x);
            min.y = Mathf.Min(vertex.y, min.y);
            min.z = Mathf.Min(vertex.z, min.z);

            max.x = Mathf.Max(vertex.x, max.x);
            max.y = Mathf.Max(vertex.y, max.y);
            max.z = Mathf.Max(vertex.z, max.z);
        }
        Vector3 size = max - min;
        Vector3 center = (max + min) / 2;

        BoxCollider bc = go.AddComponent<BoxCollider>();
        bc.size = size;
        bc.center = center;
        m_Colliders.Add(bc);
        m_SelectedVerts.Clear();
        go.layer = colliderLayer;
    }

19 Source : Fractal.cs
with MIT License
from alchemz

private void Start()
	{
		rotationSpeed = Random.Range (-maxRotationSpeed, maxRotationSpeed);
		transform.Rotate (Random.Range (-maxTwist, maxTwist), 0f, 0f);
		if (materials == null) {
			InitializeMaterials();
		}
		gameObject.AddComponent<MeshFilter>().mesh =
			meshes[Random.Range(0, meshes.Length)];
		gameObject.AddComponent<MeshRenderer>().material = 
		materials[depth, Random.Range (0, 2)];
		if (depth < maxDepth) {
			StartCoroutine(CreateChildren());
		}
	}

19 Source : Fractal.cs
with MIT License
from alchemz

private IEnumerator CreateChildren()
	{
		for (int i = 0; i < childDirections.Length; i++) {
			if (Random.value < spawnProbablity) {
				yield return new WaitForSeconds (Random.Range (0.1f, 0.5f));
				new GameObject ("FractalChild").AddComponent<Fractal> ().
			Initialize (this, i);
			}
		}
	}

See More Examples