示例#1
0
        public void GameObjectComponentRemoval()
        {
            CoroutineController controller = new CoroutineController();
            GameObject gameObject = new GameObject(controller);

            Assert.AreEqual(gameObject.Count, 2, "Initial count was not two, as it should've been.");

            gameObject.Remove(controller);

            Assert.AreEqual(gameObject.Count, 1, "Count after removal wasn't one, as it should've been (as only the Transform should be left attached).");
        }
示例#2
0
	IEnumerator PlayDestructionParticleFX(GameObject parent) {
		GameObject particleFX = Instantiate(References.DestructionParticleFX, parent.transform.position, Quaternion.identity) as GameObject;
		particleFX.transform.parent = parent.transform;
		particleFX.transform.position = parent.transform.position - new Vector3(0, 0, 1);
		ParticleSystem particles = particleFX.GetComponentInChildren<ParticleSystem>();
		
		if (particles != null) {
			particles.Play();
		
			while (particles != null && particles.isPlaying) {
				yield return new WaitForSeconds(0);
			}
		
			parent.Remove();
		}
	}
示例#3
0
        static void CreateSprite()
        {
            if (System.Array.TrueForAll(Selection.objects, selected => !(selected is Texture)))
            {
                Logger.LogError("No sprites were selected.");
                return;
            }

            for (int i = 0; i < Selection.objects.Length; i++)
            {
                Texture texture = Selection.objects[i] as Texture;

                if (texture == null)
                {
                    continue;
                }

                string textureName  = texture.name.EndsWith("Texture") ? texture.name.Substring(0, texture.name.Length - "Texture".Length) : texture.name;
                string texturePath  = AssetDatabase.GetAssetPath(texture);
                string materialPath = Path.GetDirectoryName(texturePath) + "/" + textureName + ".mat";

                Sprite sprite = AssetDatabase.LoadAssetAtPath(texturePath, typeof(Sprite)) as Sprite;

                if (sprite == null)
                {
                    Logger.LogError(string.Format("Texture {0} must be imported as a sprite.", texture.name));
                    continue;
                }

                AssetDatabase.CopyAsset(HelperFunctions.GetAssetPath("GraphicsTools/SpriteMaterial.mat"), materialPath);
                AssetDatabase.Refresh();

                Material material = AssetDatabase.LoadAssetAtPath(materialPath, typeof(Material)) as Material;

                GameObject     gameObject     = new GameObject(textureName);
                GameObject     child          = gameObject.AddChild("Sprite");
                SpriteRenderer spriteRenderer = child.AddComponent <SpriteRenderer>();

                spriteRenderer.sprite   = sprite;
                spriteRenderer.material = material;

                PrefabUtility.CreatePrefab(Path.GetDirectoryName(texturePath) + "/" + textureName + ".prefab", gameObject);
                AssetDatabase.Refresh();

                gameObject.Remove();
            }
        }
示例#4
0
        public override void Update(CanvasContext2D context)
        {
            List <PlasmaBall> garbage = new List <PlasmaBall>();

            foreach (PlasmaBall plasmaBall in _plasmaBalls)
            {
                plasmaBall.Update();
                if (!plasmaBall.Intersect(0, 0, 900, 600) || plasmaBall.Destroyed)
                {
                    garbage.Add(plasmaBall);
                }
            }

            foreach (PlasmaBall junk in garbage)
            {
                GameObject.Remove(junk);
                _plasmaBalls.Remove(junk);
            }
        }
示例#5
0
    void createIfShouldExistElseRemove(GameObject prefabObject, string name, bool shouldExist)
    {
        GameObject go = GameObject.Find(name);

        if (shouldExist)
        {
            if (go == null)
            {
                GameObjectFactory.createCopyGameObject(prefabObject, name);
            }
        }
        else
        {
            if (go != null)
            {
                go.Remove();
            }
        }
    }
示例#6
0
        public override void Update(CanvasContext2D context)
        {
            List <Projectile> garbage = new List <Projectile>();

            foreach (Projectile projectile in _projectiles)
            {
                projectile.Update();
                if (!projectile.Intersect(0, 0, 800, 600) || projectile.Destroyed)
                {
                    garbage.Add(projectile);
                }
            }

            foreach (Projectile junk in garbage)
            {
                junk.Removed();
                GameObject.Remove(junk);
                _projectiles.Remove(junk);
            }
        }
 /// <summary>
 /// Resets the soldier
 /// </summary>
 /// <param name="soldier">Soldier to reset</param>
 private void ResetSoldier(GameObject soldier)
 {
     soldier.Get<HealthComponent>().Life = HealthComponent.MaxLife;
     soldier.Get<ShieldComponent>().Power = ShieldComponent.MaxPower;
     soldier.Remove<PoisonComponent>();
 }
示例#8
0
 public void GameObjectComponentRemovalValidators()
 {
     Transform t = new Transform();
     GameObject gameObject = new GameObject(t);
     Assert.IsFalse(gameObject.Remove(t), "Component was successfully removed, this is not the expected behaviour.");
 }
示例#9
0
        public Game1()
        {
            instance = this;
            graphics = new GraphicsDeviceManager(this);
            Content.RootDirectory = "Content";
            world = new GameObject(Objects.Empty, false)
            {
                multiplayer = true
            };

            editorGUI = new GameObject(Objects.Empty, false)
            {
                multiplayer = false
            };

            gizmoWorld = new GameObject(Objects.Empty, false)
            {
                multiplayer = false
            };

            userGUI = new GameObject(Objects.Empty, false)
            {
                multiplayer = false
            };

            IsMouseVisible = true;
            camera         = new Camera();
            WMouse.camera  = camera;

            worldActionScript = new WUIShared.WUIWorldActionScript();
            worldActionScript.Bind("KeyDown", (args) => {
                Enum.TryParse((string)args[0], out Keys key);
                return(WKeyboard.currentKeyboardState.IsKeyDown(key) ? 1 : 0);
            });
            worldActionScript.Bind("KeyClick", (args) => {
                Enum.TryParse((string)args[0], out Keys key);
                return(WKeyboard.KeyClick(key) ? 1 : 0);
            });
            worldActionScript.Bind("ClientOwnedIs", (args) => {
                return(((GameObject)args[0]).ClientOwned ? 1 : 0);
            });
            worldActionScript.Bind("LocalPlayerIs", (args) => {
                return(localPlayer == ((GameObject)args[0]));
            });
            worldActionScript.Bind("LocalPlayerGet", (args) => {
                if (localPlayer == null)
                {
                    return(0);
                }
                return(worldActionScript.GetVariable(new string[] { localPlayer.name }));
            });
            worldActionScript.Bind("LocalPlayerSet", (args) => {
                localPlayer = ((GameObject)args[0]);
                return(null);
            });
            worldActionScript.Bind("LocalPlayerExists", (args) => localPlayer != null ? 1 : 0);
            worldActionScript.Bind("ParentSetToUI", (args) => {
                GameObject gameObject = ((GameObject)args[0]);
                if (gameObject.Parent != userGUI)
                {
                    return(1);                              // You are in UI!
                }
                gameObject.Remove(false, false);
                userGUI.AddChild(gameObject);
                return(0);
            });
            //MouseStuff
            worldActionScript.Bind("MouseGetWorldX", (args) => (int)WMouse.WorldPosition.X);
            worldActionScript.Bind("MouseGetWorldY", (args) => (int)WMouse.WorldPosition.Y);
            worldActionScript.Bind("MouseGetScreenX", (args) => (int)WMouse.Position.X);
            worldActionScript.Bind("MouseGetScreenY", (args) => (int)WMouse.Position.Y);
            worldActionScript.Bind("MouseLeftDown", (args) => (int)WMouse.mouseState.LeftButton);
            worldActionScript.Bind("MouseRightDown", (args) => (int)WMouse.mouseState.RightButton);
            worldActionScript.Bind("MouseLeftClick", (args) => WMouse.RightMouseClick() ? 1 : 0);
            worldActionScript.Bind("MouseRightClick", (args) => WMouse.LeftMouseClick() ? 1 : 0);
            worldActionScript.Bind("MouseOverObject", (args) => ((MouseClickableComponent)args[0]).mouseClickable.MouseOver ? 1: 0);
            worldActionScript.Bind("MouseLeftClickDownObject", (args) => ((MouseClickableComponent)args[0]).mouseClickable.MouseLeftClickDown ? 1 : 0);
            worldActionScript.Bind("MouseRightClickUpObject", (args) => ((MouseClickableComponent)args[0]).mouseClickable.MouseLeftClickUp ? 1 : 0);
            worldActionScript.Bind("MouseLeftDownObject", (args) => (((MouseClickableComponent)args[0]).mouseClickable.MouseOver && WMouse.mouseState.LeftButton == ButtonState.Pressed) ? 1 : 0);
            worldActionScript.Bind("MouseRightDownObject", (args) => (((MouseClickableComponent)args[0]).mouseClickable.MouseOver && WMouse.mouseState.RightButton == ButtonState.Pressed) ? 1 : 0);

            string[] config = File.ReadAllLines("Config.txt");
            client                    = new ClientBase(config[0], int.Parse(config[1]), 8388608); //8MB Of buffer so images can be sent.
            assetManager              = new ClientAssetManager(client);
            networkManager            = new NetworkManager(world);
            GameObject.networkManager = networkManager;
        }
 public static void Remove <T>(this GameObject source) where T : Component
 {
     source.Remove(source.GetComponent <T>());
 }