public virtual void OnExit(GameObject exited)
 {
     Entity e = exited.GetComponentInParent<Entity>();
     if (e)
     {
         entitiesInContact.Remove(e);
     }
 }
        void Awake()
        {
            On("OnMainCameraChange");

            _healthContainer = GetComponentInChildren<Image>().gameObject;
            _healthContainer.GetComponentInParent<Canvas>().worldCamera = Camera.main;
            _rectTransform = _healthContainer.GetComponent<RectTransform>();
            _healthBar = _healthContainer.transform.FindChild("HealthBar").GetComponent<RectTransform>();
            _image = _healthBar.GetComponent<Image>();
            _krHealth = transform.GetComponentInParent<KRHealth>();
        }
Example #3
0
		void OnParticleCollision(GameObject shooter) {
			//print ( "OnParticleCollision  " + other.transform.root.name + " ME : " + transform.root.name);

			shooterCombat = shooter.transform.root.GetComponent<Combat>();
		
			if (shooterCombat != myCombat && shooterCombat.isLocalPlayer) {
				shooterCombat.GiveDamage ( shooter.GetComponentInParent<Weapon>().damage , transform.root.name , DamageType.Smell , Vector3.zero , Vector2.zero );
				//myCombat.TakeDamage ( shooter.GetComponentInParent<Weapon>().damage , transform.root.name , DamageType.Smell , Vector3.zero , Vector2.zero );
			}
				
		}
 public virtual void OnTouch(GameObject touched)
 {
     Entity e = touched.GetComponentInParent<Entity>();
     if (e)
     {
         if (!entitiesInContact.Contains(e))
         {
             attack.Execute(DamageInfo.DamageType.physical, damageModifierOnTouch, e);
             entitiesInContact.Add(e);
             StartCoroutine(_OnContinuousTouch(e));
         }
     }
 }
Example #5
0
		public bool TryToPickup(GameObject obj) {
			var new_item = obj.GetComponent<Rigidbody> ();
			if (new_item == null)
				new_item = obj.GetComponentInParent<Rigidbody> ();

			if (new_item != null && !new_item.isKinematic) {
				Pickup (new_item);
				return true;
			} else {
				Debug.Log ("Can't pick up " + obj.name);
				return false;
			}
		}
		protected IInteractionActor GetActor(GameObject other) {
			if (!_cachedActorMap.ContainsKey(other)) {
				// cache miss - grab from other object using GetComponent
				IInteractionActor actor = other.GetComponentInParent<IInteractionActor>();

				if (actor == null) {
					Debug.LogError("InteractionZone entered by GameObject without InteractionZoneActor script");
					return null;
				}
				
				_cachedActorMap[other] = actor;
			}
			
			return _cachedActorMap[other];
		}
		private static void SetupObject(string objectName)
		{
			selectedObject = Selection.activeGameObject;
			theThing.name = objectName;

			if (selectedObject)
			{
				if (GameObject.Find(selectedObject.name))
				{
					if (selectedObject.GetComponentInParent<Canvas>())
						notCanvas = false;
					else
						notCanvas = true;
				}
				else
					notCanvas = true;
			}
			else
				notCanvas = true;

			if (notCanvas)
			{
				if (!GameObject.FindObjectOfType<UnityEngine.EventSystems.EventSystem>())
				{
					GameObject.Instantiate(AssetDatabase.LoadAssetAtPath("Assets/MaterialUI/ComponentPrefabs/EventSystem.prefab",
						typeof (GameObject))).name = "EventSystem";
				}

				if (GameObject.FindObjectOfType<Canvas>())
				{
					selectedObject = GameObject.FindObjectOfType<Canvas>().gameObject as GameObject;
				}
				else
				{
					selectedObject =
						GameObject.Instantiate(AssetDatabase.LoadAssetAtPath("Assets/MaterialUI/ComponentPrefabs/Canvas.prefab",
							typeof (GameObject))) as GameObject;
					selectedObject.name = "Canvas";
				}
			}

			theThing.transform.SetParent(selectedObject.transform);
			theThing.transform.localPosition = Vector3.zero;
			theThing.transform.localScale = new Vector3(1, 1, 1);
			Selection.activeGameObject = theThing;
		}
Example #8
0
        private ItemInfo GetItemInfo(GameObject selected)
        {
            if (selected == null) return null;

            foreach (var info in _items)
            {
                if (info.Control == selected)
                    return info;
            }

            //we only use the first parent, in the case of nested listboxes
            var parentItem = selected.GetComponentInParent<ListBoxItem>();
            var parent = parentItem == null ? null : parentItem.gameObject;
            foreach(var info in _items)
            {
                if (info.Control == parent)
                    return info;
            }

            return null;
        }
Example #9
0
		void Start () {
			cameraAudio = GetComponent<AudioSource> ();

			parent = GameObject.Find("PlayerCam");
			cameraHeldUp   = new Vector3( 0.009f, 0.030f,-0.100f);
            cameraHeldDown = new Vector3( 0.293f,-0.499f, 0.300f);

			photoReview = false;

			// Set portrait lens
			/*curLens = GameObject.Find (currentLens);
			curLens.GetComponent<MeshRenderer> ().enabled = true;

			parent.GetComponentInParent<DepthOfField> ().focalSize = curLens.GetComponent<Lens> ().focalSize;
			parent.GetComponentInParent<DepthOfField> ().focalLength = curLens.GetComponent<Lens> ().focalDistance;
			parent.GetComponentInParent<Camera> ().fieldOfView = curLens.GetComponent<Lens> ().fieldOfView;
*/
			FilterPrefab.SetActive (false);

			lensIter = 0;
			filterIter = 0;

			memCardReader = GameObject.Find("/MemoryCardManager").GetComponent<MemoryCardReader>();

			PlayerProfile.profile.load ();
			currentLens = PlayerProfile.profile.lensesInBag[0];
			curLens = GameObject.Find (currentLens);
			curLens.GetComponent<MeshRenderer> ().enabled = true;

			parent.GetComponentInParent<DepthOfField> ().focalSize = curLens.GetComponent<Lens> ().focalSize;
			parent.GetComponentInParent<DepthOfField> ().focalLength = curLens.GetComponent<Lens> ().focalDistance;
			parent.GetComponentInParent<Camera> ().fieldOfView = curLens.GetComponent<Lens> ().fieldOfView;
			/*foreach (string s in PlayerProfile.profile.lensesInBag) {
				Debug.Log ("Lens " + s);
			}
			foreach (string s in PlayerProfile.profile.filtersInBag) {
				Debug.Log ("Filters " + s);
			}*/
		}
        private void DoCollide(GameObject collidedObject)
        {
            Collider other = collidedObject.GetComponent<Collider>();
            if (ignoreColliders != null && ignoreColliders.Contains(other))
                return;

            IInteractable interactable = collidedObject.GetComponentInParent<IInteractable>();

            if (interactable != null)
            {
                if (interactable is Entity)
                {
                    CharController controller = collidedObject.GetComponent<CharController>();
                    if (controller) controller.Hit();
                }

                float strBonus = str ? str.Value * 0.5f : 0;
                AttackAction attack = owner.GetComponent<AttackAction>();

                if (attack)
                    attack.Execute(strBonus, interactable);
            }
            SimulateImpact(collidedObject, impactMultiplier, true);
        }
Example #11
0
        /// <summary>
        /// Create the content of a board, which content is a set of TextButton.
        /// </summary>
        /// <param name="texts">The text array should be displayed on a set of TextButtons</param>
        /// <param name="buttonPrefab">prefab of the TextButton, which could be customized by developers</param>
        /// <param name="contentGameObject">parent GameObject that the created a set of TextButtons should be child of</param>
        /// <param name="toBottom">whether the content of board should scroll to bottom when shown</param>
        /// <param name="onclick">function to be called when responding TextButton is clicked</param>
        /// <param name="parameters">parameter array should be attached to the TextButton and would be passed to the on click function</param>
        public void setupTextButtonBoard(List<string> texts, GameObject buttonPrefab, GameObject contentGameObject, bool toBottom, UnityAction<bool, System.Object> onclick, List<System.Object> parameters)
        {
            //Destroy all previous text buttons
            for (int i = 0; i < contentGameObject.transform.childCount; i++) {
                GameObject.Destroy(contentGameObject.transform.GetChild(i).gameObject);
            }

            //Create a list of log text button
            List<GameObject> textButtons = new List<GameObject>();
            for (int i = 0; i < texts.Count; i++) {
                GameObject newTextButton = this.createTextButton(texts[i], buttonPrefab, contentGameObject, onclick, parameters[i]);
                if (textButtons.Count > 0) {
                    newTextButton.transform.localPosition = textButtons[textButtons.Count - 1].transform.localPosition;
                    newTextButton.transform.localPosition = new Vector3(newTextButton.transform.localPosition.x,
                                                                    newTextButton.transform.localPosition.y - newTextButton.GetComponent<RectTransform>().rect.height*1f,
                                                                    newTextButton.transform.localPosition.z);
                }
                textButtons.Add(newTextButton);
            }

            //Resize the backLogText
            float height = (textButtons.Count + 1) * textButtons[0].GetComponent<RectTransform>().rect.height;
            float width = contentGameObject.GetComponent<RectTransform>().rect.width;
            contentGameObject.GetComponent<RectTransform>().sizeDelta = new Vector2(width, height);

            //Scroll to the bottom
            if (toBottom) {
                contentGameObject.GetComponentInParent<ScrollRect>().normalizedPosition = new Vector2(0, 0);
            }
        }
 GameObject ExtractRootParentFrom(GameObject theObject)
 {
     // try to get the player GameObject from this Flowchart's GameObject
     Persona personaScript = theObject.GetComponent<Persona>();
     // if it wasn't there
     if (personaScript == null)
     {
         // try to get the Persona from this flowchart's parents
         personaScript = theObject.GetComponentInParent<Persona>();
     }
     // if we found the Persona component
     if (personaScript != null)
     {   // return it's GameObject
         return personaScript.gameObject;
     }
     // couldn't find it (this is an error
     Debug.LogError("Couldn't find root parent object");
     return null;
 }
Example #13
0
        public virtual void MouseClick(GameObject hitGameObject, Vector3 hitPoint, Player player)
        {
            if (isSelected == false)
            {
                return;
            }
            if (hitGameObject == null)
            {
                return;
            }
            bool isGround = hitGameObject.CompareTag(Tags.GROUND);
            if (isGround == true)
            {
                return;
            }

            Destructible hitEntity = hitGameObject.GetComponentInParent<Destructible>();
            if (hitEntity == null)
            {
                return;
            }
            if (hitEntity == this)
            {
                return;
            }

            bool readyToAttack = IsAbleToAttack();
            if (readyToAttack == false)
            {
                ChangeSelection(hitEntity, player);
                return;
            }

            if (hitEntity.MaxHitPoints == 0)
            {
                ChangeSelection(hitEntity, player);
                return;
            }

            Player hitEntityOwner = hitEntity.Owner;
            if (hitEntityOwner != null)
            {
                bool samePlayer = Owner.PlayerId == hitEntityOwner.PlayerId;
                if (samePlayer == true)
                {
                    ChangeSelection(hitEntity, player);
                    return;
                }
            }

            SetAttackTarget(hitEntity);
        }
Example #14
0
 public Loot(GameObject agent, GameObject cell)
     : base(agent, TaskType.Loot)
 {
     this.cell = cell;
     hive = cell.GetComponentInParent<HiveWarehouse>();
 }
Example #15
0
        private static bool CreateGameObject(out GameObject created)
        {
            created = Selection.activeGameObject;

            if (created != null && created.GetComponentInParent<Canvas>() != null && EditorApplication.ExecuteMenuItem("GameObject/Create Empty Child"))
            {
                created = Selection.activeGameObject;
                return true;
            }
            else if (EditorApplication.ExecuteMenuItem("GameObject/UI/Image"))
            {
                created = Selection.activeGameObject;
                GameObject.DestroyImmediate(created.GetComponent<Image>());
                GameObject.DestroyImmediate(created.GetComponent<CanvasRenderer>());
                return true;
            }
            else
            {
                return false;
            }
        }
 /// <summary>
 /// Finds the part by the GameObject belongs to.
 /// </summary>
 /// <param name="gameObject">GameObject of a part</param>
 /// <returns>the part</returns>
 /// <remarks>Thanks goes to xEvilReeperx! :-)</remarks>
 /// <see cref="http://forum.kerbalspaceprogram.com/threads/7544-The-official-unoffical-help-a-fellow-plugin-developer-thread?p=2124761&viewfull=1#post2124761"/>
 public Part GetPartByGameObject(GameObject gameObject)
 {
     return gameObject.GetComponentInParent<Part>();
 }
Example #17
0
        public virtual void SetHoverState(GameObject gameObjectUnderMouse)
        {
            if (Owner == null)
            {
                return;
            }
            if (Owner.IsNPC == true)
            {
                return;
            }
            if (isSelected == false)
            {
                return;
            }

            bool isGround = gameObjectUnderMouse.CompareTag(Tags.GROUND);
            if (isGround == true)
            {
                return;
            }

            Owner.PlayerHud.SetCursorState(CursorState.select);

            bool canAttack = IsAbleToAttack();
            if (canAttack == false)
            {
                return;
            }

            Destructible entityUnderMouse = gameObjectUnderMouse.GetComponentInParent<Destructible>();
            if (entityUnderMouse == null)
            {
                return;
            }

            if (entityUnderMouse.MaxHitPoints == 0)
            {
                return;
            }

            Player entityOwner = entityUnderMouse.Owner;
            if (entityOwner != null)
            {
                bool samePlayer = Owner.PlayerId == entityOwner.PlayerId;
                if (samePlayer == true)
                {
                    return;
                }
            }

            Owner.PlayerHud.SetCursorState(CursorState.attack);
        }
 /// <summary>
 /// The IsObjectInteractable method is used to check if a given game object is of type `VRTK_InteractableObject` and whether the object is enabled.
 /// </summary>
 /// <param name="obj">The game object to check to see if it's interactable.</param>
 /// <returns>Is true if the given object is of type `VRTK_InteractableObject`.</returns>
 public bool IsObjectInteractable(GameObject obj)
 {
     if (obj)
     {
         var io = obj.GetComponent<VRTK_InteractableObject>();
         if (io)
         {
             return io.enabled;
         }
         else
         {
             io = obj.GetComponentInParent<VRTK_InteractableObject>();
             if (io)
             {
                 return io.enabled;
             }
         }
     }
     return false;
 }
Example #19
0
 void setQuit()
 {
     // 游戏的外环顺时针旋转;
     mGo_Quit_parent.transform.localPosition = Vector3.zero;
     GameObject go = mGo_Quit_parent.transform.FindChild("fruitparent/ring").gameObject;
     Framework.SetRotate(go, 10f, true);
     Framework.SetScale(go);
     AddRing(go);
     // 游戏的水果逆时针旋转;
     Vector3 vec = mGo_Quit_parent.transform.FindChild("fruitparent").localPosition;
     if(mGo_Quit==null)
     {
         mGo_Quit = Framework.CreateUIFruit(mGo_Quit_parent, fruitType.boom, vec);
         FruitItem fuit = mGo_Quit.GetComponentInParent<FruitItem>();
         Framework.AddOnClick(mGo_Quit, "", OnQuit);
     }          
 }
        private static void CreateToolTipItem(bool select, GameObject parent)
        {
            var btti = Object.FindObjectOfType<BoundTooltipItem>();
            if (btti == null)
            {
                var boundTooltipItem = CreateUIObject("ToolTipItem", parent.GetComponentInParent<Canvas>().gameObject);
                btti = boundTooltipItem.AddComponent<BoundTooltipItem>();
                var boundTooltipItemCanvasGroup = boundTooltipItem.AddComponent<CanvasGroup>();
                boundTooltipItemCanvasGroup.interactable = false;
                boundTooltipItemCanvasGroup.blocksRaycasts = false;
                var boundTooltipItemImage = boundTooltipItem.AddComponent<Image>();
                boundTooltipItemImage.sprite = AssetDatabase.GetBuiltinExtraResource<Sprite>(kBackgroundSpriteResourcePath);
                var boundTooltipItemText = CreateUIObject("Text", boundTooltipItem);
                var boundTooltipItemTextRT = boundTooltipItemText.GetComponent<RectTransform>();
                boundTooltipItemTextRT.anchorMin = Vector2.zero;
                boundTooltipItemTextRT.anchorMax = Vector2.one;
                boundTooltipItemTextRT.sizeDelta = Vector2.one;
                var boundTooltipItemTextcomponent = boundTooltipItemText.AddComponent<Text>();
                boundTooltipItemTextcomponent.alignment = TextAnchor.MiddleCenter;
                Undo.RegisterCreatedObjectUndo(boundTooltipItem, "Create " + boundTooltipItem.name);
            }

            if (select && btti != null)
            {
                Selection.activeGameObject = btti.gameObject;
            }
        }
		public bool CanBuild(GameObject hierarchySelection)
		{
			Canvas parentCanvas = hierarchySelection.GetComponentInParent<Canvas>();
			return parentCanvas != null;
		}
        private void StopTouching(GameObject obj)
        {
            if (IsObjectInteractable(obj))
            {
                GameObject untouched;
                if (obj.GetComponent<VRTK_InteractableObject>())
                {
                    untouched = obj;
                }
                else
                {
                    untouched = obj.GetComponentInParent<VRTK_InteractableObject>().gameObject;
                }

                OnControllerUntouchInteractableObject(SetControllerInteractEvent(untouched.gameObject));
                untouched.GetComponent<VRTK_InteractableObject>().ToggleHighlight(false);
                untouched.GetComponent<VRTK_InteractableObject>().StopTouching(this.gameObject);
            }

            if (hideControllerOnTouch)
            {
                controllerActions.ToggleControllerModel(true, touchedObject);
            }
            touchedObject = null;
        }
 private bool IsColliderChildOfTouchedObject(GameObject collider)
 {
     if (touchedObject != null && collider.GetComponentInParent<VRTK_InteractableObject>() && collider.GetComponentInParent<VRTK_InteractableObject>().gameObject == touchedObject)
     {
         return true;
     }
     return false;
 }
Example #24
0
 /////////////////////////////////////////
 // OnEntityBuilt(Planner planner, GameObject gameobject)
 // Called when a buildingblock was created
 /////////////////////////////////////////
 private void OnEntityBuilt(Planner planner, GameObject gameobject)
 {
     if (planner.ownerPlayer == null) return;
     if (HasPlayerFlag(planner.ownerPlayer, ZoneFlags.NoBuild) && !hasPermission(planner.ownerPlayer, PermCanBuild))
     {
         gameobject.GetComponentInParent<BaseCombatEntity>().Kill(BaseNetworkable.DestroyMode.Gib);
         SendMessage(planner.ownerPlayer, "You are not allowed to build here");
     }
 }
Example #25
0
 /// <summary>
 /// Returns all of the ISystems that are associated with the LevelDesigner that is
 /// hierarchically associated with the given selected object.
 /// </summary>
 private List<ISystem> GetSystems(GameObject selected)
 {
     var designer = selected.GetComponentInParent<LevelDesigner>();
     return designer.Snapshot.Systems;
 }
        private bool ShouldIgnoreElement(GameObject obj, string ignoreCanvasWithTagOrClass, VRTK_TagOrScriptPolicyList canvasTagOrScriptListPolicy)
        {
            var canvas = obj.GetComponentInParent<Canvas>();
            if (!canvas)
            {
                return false;
            }

            return (Utilities.TagOrScriptCheck(canvas.gameObject, canvasTagOrScriptListPolicy, ignoreCanvasWithTagOrClass));
        }
Example #27
0
 /////////////////////////////////////////
 // OnEntityBuilt(Planner planner, GameObject gameobject)
 // Called when a buildingblock was created
 /////////////////////////////////////////
 void OnEntityBuilt(Planner planner, GameObject gameobject)
 {
     if (planner.ownerPlayer == null) return;
     if (hasTag(planner.ownerPlayer, "nobuild"))
     {
         if (!hasPermission(planner.ownerPlayer, "canbuild"))
         {
             gameobject.GetComponentInParent<BaseCombatEntity>().Kill(BaseNetworkable.DestroyMode.Gib);
             SendMessage(planner.ownerPlayer, "You are not allowed to build here");
         }
     }
 }
        /// <summary>
        /// Attempts to hit an object by raycast onto it first, then
        /// destroying that ship part (if ship part) and applies a force
        /// in the direction of this game object's forward vector
        /// </summary>
        /// <param name="a_gameObject">Which game object to alert of collisions</param>
        private void HitObject(GameObject a_gameObject)
        {
            RaycastHit raycastHit;
            if (!Physics.Raycast(m_transform.position, m_transform.forward,
                    out raycastHit, m_collider.height, collisionLayerMask))
            {
                // Didn't collide with object
                return;
            }

            // Get player rigid body
            Rigidbody objectRigidBody = a_gameObject.GetComponentInParent<Rigidbody>();
            if (objectRigidBody == null)
            {
                Debug.Log("Can't find rigid body on collided object");
            }

            // Apply colliding force to player
            objectRigidBody.AddForce(m_transform.forward * collisionForce, ForceMode.Impulse);
            Debug.Log("Cannon ball collided with: " + objectRigidBody.name + " (tag: " + objectRigidBody.tag + ")");

            // Attempt to destroy player part
            ShipPartDestroy partDestroyer = a_gameObject.GetComponentInParent<ShipPartDestroy>();
            if (partDestroyer == null)
            {
                // Not destructable player part
                return;
            }

            // Destroy player part
            partDestroyer.EvaluatePartCollision(a_gameObject.GetComponent<Collider>(), collisionForce * 2.0f);
        }
 public bool IsObjectInteractable(GameObject obj)
 {
     return (obj && (obj.GetComponent<VRTK_InteractableObject>() || obj.GetComponentInParent<VRTK_InteractableObject>()));
 }
        private void SimulateImpact(GameObject other, Vector2 multiplier, bool zeroVelocity = false)
        {
            Rigidbody body = other.GetComponentInParent<Rigidbody>();
            if (body)
            {
                if (zeroVelocity)
                    body.velocity = Vector3.zero;

                Vector3 dir = other.transform.position - transform.position;
                dir.y = 0;
                dir.Normalize();

                float strModifier = str ? str.Value : 1;
                body.AddForce((dir * multiplier.x + Vector3.up * multiplier.y) * strModifier, modeOnImpact);
            }
        }