protected override void OnEnable() { base.OnEnable(); this.m_Animator.SetBool(this.m_CarryingWaterHash, true); this.m_Container = (LiquidContainer)this.m_Player.GetCurrentItem(Hand.Right); DebugUtils.Assert(this.m_Container != null, "[LiquidInHandsController:OnEnable] ERROR - Currentitem is not a LiquidContainer!", true, DebugUtils.AssertType.Info); }
private void OnNetCreate(NetCreatePacket obj) { //Debug.Log($"[Client] - NetObject {obj.TypeName} created with id {obj.NetID} and parent id {obj.ParentID}"); DebugUtils.Assert(!NetObjectExists(obj.NetID), $"Net object with id {obj.NetID} already exists on the client."); var netObj = new INetObject(this, obj.NetObjectType, obj.EntityType, obj.NetID, obj.CreateData); netObjects.Add(obj.NetID, netObj); // If the corresponding obj has a parent, then we need to go up the chain // of parents and find the first one that has an OnCreate method defined // for this type of net object. If we don't find anything, then this net // object becomes its own Game Object with the NetObject component. if (obj.ParentID != -1) { netObj.SetParent(obj.ParentID); netObjects[obj.ParentID].AddChild(netObj.NetID); // Recursively try and find parent that handles creation of this type // If no parents have defined a handler, then we need to create a game object // with a NetObject component. if (TryParentCreate(obj.ParentID, netObj)) { return; } } netObj.IsGameObject = true; var go = CreateGameObject(netObj); }
public override void ReplOnChangedOwner(bool was_owner) { GameObject gameObject = Player.Get().gameObject; DebugUtils.Assert(gameObject, true); this.m_LocalPlayerTransform = gameObject.GetComponent <Transform>(); }
/// <summary> /// Returns the possible transitions from this state. /// </summary> /// <param name="agent">The agent we're searching a path for.</param> public List <ITransition> GetPossibleTransitions(ISearchContext agent) { var goapAgent = agent as GoapAgent; DebugUtils.Assert(goapAgent != null, "Expected GoapAgent but got " + agent); var possibleActions = new List <ITransition>(); var availableActions = goapAgent.availableActions; foreach (var action in availableActions) { if (!IsGoalState(action.GetIndependentPreconditions(goapAgent))) { // Action does not apply to this state. //DebugUtils.LogError("Action: " + action + " does not apply to agent"); continue; } var targets = action.GetAllTargets(goapAgent); //DebugUtils.LogError("Checking Action: " + GoapAgent.PrettyPrint(action) + " got targets: " + targets.Count); foreach (var target in targets) { if (goapAgent != (target as GoapAgent) && !IsGoalState(action.GetDependentPreconditions(goapAgent, target))) { // Action does not apply to this target. //DebugUtils.LogError("Action does not apply for target: " + (target as Component).name); continue; } possibleActions.Add(GoapAction.WithContext.Borrow(action, goapAgent, target)); } } return(possibleActions); }
public void SoundEvent(string sound_name) { if (!this.m_AudioSource) { return; } if (!this.m_Sounds.ContainsKey(sound_name)) { DebugUtils.Assert("Can't find sound - " + sound_name, true, DebugUtils.AssertType.Info); return; } List <AudioClip> list = this.m_Sounds[sound_name]; if (list.Count == 0) { DebugUtils.Assert("Missing clips of sound - " + sound_name, true, DebugUtils.AssertType.Info); return; } AudioClip audioClip = list[UnityEngine.Random.Range(0, list.Count)]; if (this.m_HumanAI) { this.m_HumanAI.m_HumanAISoundModule.PlaySound(audioClip); return; } this.m_AudioSource.Stop(); this.m_AudioSource.clip = audioClip; this.m_AudioSource.Play(); if (this.m_Log) { CJDebug.Log("SoundEvent " + audioClip.name); } }
//Based on https://en.wikipedia.org/wiki/Topological_sorting#Depth-first_search, but with reversed logic and loop resolution. private List <CircuitNode> OrderDfsR() { Dictionary <CircuitNode, DfsMark> marks = new Dictionary <CircuitNode, DfsMark>(); //A simple array should work too foreach (CircuitNode n in nodes) { marks.Add(n, DfsMark.Unmarked); } List <CircuitNode> L = new List <CircuitNode>(); Stack <CircuitNode> path = new Stack <CircuitNode>(); HashSet <Connection> removedEdges = new HashSet <Connection>(); foreach (CircuitNode n in nodes) { if (marks[n] != DfsMark.Unmarked) { continue; } DebugUtils.Assert(ReferenceEquals(n, nodes.First(cn => marks[cn] == DfsMark.Unmarked))); OrderDfsRVisit0(n, marks, L, path, removedEdges); DebugUtils.Assert(marks[n] == DfsMark.Permanent); } DebugUtils.Assert(!nodes.Any((CircuitNode n) => marks[n] != DfsMark.Permanent)); return(L); }
public override void SetSetting(NodeSetting setting, object value) { if (setting.type != NodeSetting.SettingType.NodeDataType) { base.SetSetting(setting, value); } else { if (value == setting.currentValue) { return; } setting.currentValue = value; Type newType = ((NodeSetting.DataType)value).SytemType; for (int i = 1; i < settings.Length; i++) { NodeSetting s = settings[i]; s.valueType = newType; try { s.currentValue = Convert.ChangeType(s.currentValue, newType); } catch (FormatException) { s.currentValue = Activator.CreateInstance(newType); } DebugUtils.Assert(s.currentValue != null); DebugUtils.Assert(s.currentValue.GetType() == newType); } EmitEvaluationRequired(); } }
protected override void OnEnable() { base.OnEnable(); Item currentItem = this.m_Player.GetCurrentItem(Hand.Right); DebugUtils.Assert(currentItem && currentItem.m_Info.IsWeapon(), true); if (!currentItem) { this.Stop(); Player.Get().StartController(PlayerControllerType.FistFight); Player.Get().StartControllerInternal(); return; } if (!Inventory3DManager.Get().gameObject.activeSelf&& !currentItem.m_IsBeingDestroyed) { currentItem.gameObject.SetActive(false); } this.m_WasActivated = false; DebugUtils.Assert(currentItem.m_DamagerStart, true); DebugUtils.Assert(currentItem.m_DamagerEnd, true); WeaponType weaponType = ((Weapon)currentItem).GetWeaponType(); this.m_Animator.SetInteger(this.m_IWeaponType, (int)weaponType); this.SetState(WeaponControllerState.None); this.m_AlreadyHit = false; this.m_HitObjects.Clear(); this.m_HandleEndTransform = this.m_Player.transform.FindDeepChild("mixamorig:Arm.R"); }
public void OnBeginDrag(PointerEventData eventData) { if (eventData.button != 0) { return; } if (draggingLine != null) { return; } if (nodeUi && nodeUi.IsSidebarNode) { return; } PortUi srcPort = this; if (isInput && HasLines) { //connectedLines should contain exactly 1 entry. ConnectionUi entry = connectedLines[0]; entry.Disconnect(); srcPort = entry.sourcePortUi; } draggingLine = Instantiate(connectionPrefab, linesContainer).GetComponent <ConnectionUi>(); DebugUtils.Assert(draggingLine != null); draggingLine.sourcePortUi = srcPort; draggingLine.SetVirtualTargetPosition(Center); draggingLine.UpdateColors(); RRCSManager.Instance.selectionManager.SelectionEnabled = false; }
public void StartPPInterpolator(string i1, string i2, string def) { PostProcessObject[] array = Resources.FindObjectsOfTypeAll <PostProcessObject>(); PostProcessObject postProcessObject = null; PostProcessObject postProcessObject2 = null; this.m_DefaultEffect = (PostProcessManager.Effect)Enum.Parse(typeof(PostProcessManager.Effect), def); for (int j = 0; j < array.Length; j++) { if (array[j].name == i1) { postProcessObject = array[j]; break; } } for (int k = 0; k < array.Length; k++) { if (array[k].name == i2) { postProcessObject2 = array[k]; break; } } DebugUtils.Assert(postProcessObject && postProcessObject2, true); this.m_PPInterpolatorObjects[0] = postProcessObject; this.m_PPInterpolatorObjects[1] = postProcessObject2; postProcessObject.m_MaxRadius = postProcessObject.transform.position.Distance(postProcessObject2.transform.position); postProcessObject2.m_MaxRadius = postProcessObject.transform.position.Distance(postProcessObject2.transform.position); this.m_InterpolatePP = true; }
public static SpaceshipBrain GetBrain(string brainName) { if (brainName == "Random") { var names = instance.brainPools.Keys; var i = Random.Range(0, names.Count); foreach (var name in names) { // Skip the player. if (name != "Player") { brainName = name; if (i <= 0) { break; } } --i; } } DebugUtils.Assert(instance.brainPools.ContainsKey(brainName), "No brain named '" + brainName + "' in factory"); var pool = instance.brainPools[brainName]; return(pool.Get()); }
public bool IsInSwimWater(Vector3 pos, ref float water_level) { float num = float.MinValue; for (int i = 0; i < this.m_CurrentSwimWaters.Count; i++) { this.m_CurrentSwimWaters[i].gameObject.GetComponents <BoxCollider>(this.m_Colliders); BoxCollider boxCollider = null; if (this.m_Colliders.Count > 0) { boxCollider = this.m_Colliders[0]; } else { DebugUtils.Assert(DebugUtils.AssertType.Info); } float y = boxCollider.bounds.max.y; if (y > num) { num = y; } } if (this.m_CurrentSwimWaters.Count > 0) { water_level = num; return(water_level >= pos.y); } return(false); }
void EditModeUpdate() { // Just a sanity check to make sure our understanding of edit/play mode behaviour is correct. DebugUtils.Assert(!EditorApplication.isPlaying, "EditModeUpdate() is not expected to be executing in play mode!"); Synchronize(); }
protected virtual void InitObjects() { for (int i = 0; i < base.transform.childCount; i++) { GameObject gameObject = base.transform.GetChild(i).gameObject; HumanAI component = gameObject.GetComponent <HumanAI>(); if (component) { this.AddAI(component); } else { Item component2 = gameObject.GetComponent <Item>(); if (component2) { component2.m_Group = this; component2.ItemsManagerUnregister(); } this.m_AllObjects.Add(gameObject); } gameObject.SetActive(this.m_Active); } if (this.m_Members.Count == 0) { UnityEngine.Object.Destroy(base.gameObject); DebugUtils.Assert("HumanAIGroup does not contains any AI!", true, DebugUtils.AssertType.Info); } }
/// <summary> /// Set the pickup type during initialization. This is set by the enemy /// </summary> private void SetPickupType() { switch (pickupType) { case PickupType.FireRate: renderer.material.color = Color.grey; break; case PickupType.BulletVel: renderer.material.color = Color.blue; break; case PickupType.SpeedBoost: renderer.material.color = Color.green; break; case PickupType.BulletDmg: renderer.material.color = Color.white; break; default: DebugUtils.Assert(false); break; } }
private void UpdateChildIdx(GameObject trigger_obj, List <int> index_list) { index_list.Clear(); GameObject gameObject = trigger_obj; if (gameObject == null) { return; } if (gameObject.ReplIsReplicable()) { return; } while (gameObject != null) { Transform parent = gameObject.transform.parent; GameObject gameObject2 = (parent != null) ? parent.gameObject : null; if (gameObject2) { index_list.Add(this.GetObjChildIndex(gameObject, gameObject2)); } gameObject = gameObject2; if (gameObject && gameObject.ReplIsReplicable()) { return; } } DebugUtils.Assert(false, "No replicated parent found for " + trigger_obj.name + "!", true, DebugUtils.AssertType.Info); }
private void EvaluateIfNecessary() { float t0 = UnityEngine.Time.realtimeSinceStartup; if (graphChanged || dbgForceReEvaluation) { graphChanged = false; EvaluateOrder(); DebugUtils.Assert(graphChanged == false); evaluationRequired = true; } if (evaluationRequired) { evaluationRequired = false; //Clearing the flag before Evaluate() allows Evaluate() to set the flag again. Evaluate(); } else { return; } float t1 = UnityEngine.Time.realtimeSinceStartup; UnityEngine.Debug.Log("Time: " + (t1 - t0)); }
//Use this to add an edge to the graph. The method will ensure that the //edge passed as a parameter is valid before adding it to the graph. If the //graph is a digraph then a similar edge connecting the nodes in the opposite //direction will be automatically added. public void AddEdge(NavGraphEdge edge) { //first make sure the from and to nodes exist within the graph DebugUtils.Assert((edge.From() < nextNodeIndex_) && (edge.To() < nextNodeIndex_), "<NavGraph::AddEdge>: invalid node index, from: " + edge.From() + ", to: " + edge.To()); //make sure both nodes are active before adding the edge if ((nodes_[edge.To()].Index() != NavGraphNode.invalid_node_index) && (nodes_[edge.From()].Index() != NavGraphNode.invalid_node_index)) { //add the edge, first making sure it is unique if (isUniqueEdge(edge.From(), edge.To())) { edges_[edge.From()].Add(edge); } //if the graph is undirected we must add another connection in the opposite //direction /* * if (!isDigraph_) { * //check to make sure the edge is unique before adding * if ( isUniqueEdge(edge.To(), edge.From()) ) { * NavGraphEdge newEdge = edge; * newEdge.SetTo(edge.From()); * newEdge.SetFrom(edge.To()); * * edges_[edge.To()].Add(newEdge); * } * } */ } }
public override void Start() { base.Start(); HumanAI humanAI = (HumanAI)this.m_AI; this.m_Animation = "Switch"; if (humanAI.m_CurrentWeapon.m_Info.IsBow()) { this.m_Animation += "Bow"; } else if (humanAI.m_CurrentWeapon.m_Info.IsKnife()) { this.m_Animation += "Knife"; } else { DebugUtils.Assert(DebugUtils.AssertType.Info); } this.m_Animation += "To"; Item item = (!(humanAI.m_CurrentWeapon == humanAI.m_PrimaryWeapon)) ? humanAI.m_PrimaryWeapon : humanAI.m_SecondaryWeapon; if (item.m_Info.IsBow()) { this.m_Animation += "Bow"; } else if (item.m_Info.IsKnife()) { this.m_Animation += "Knife"; } else { DebugUtils.Assert(DebugUtils.AssertType.Info); } }
//removes the edge connecting from and to from the graph (if present). If //a digraph then the edge connecting the nodes in the opposite direction //will also be removed. public void RemoveEdge(int fromNodeIdx, int toNodeIdx) { DebugUtils.Assert((fromNodeIdx < nodes_.Count) && (toNodeIdx < nodes_.Count), "<NavGraph::RemoveEdge>:invalid node index"); NavGraphEdge currEdge = null; /* * if (!isDigraph_) { * for ( int i=0; i<edges_[toNodeIdx].Count; ++i ) { * currEdge = edges_[toNodeIdx][i]; * if ( currEdge.To() == fromNodeIdx ) { * edges_[toNodeIdx].RemoveAt(i); * break; * } * } * } */ for (int i = 0; i < edges_[fromNodeIdx].Count; ++i) { currEdge = edges_[fromNodeIdx][i]; if (currEdge.To() == toNodeIdx) { edges_[fromNodeIdx].RemoveAt(i); break; } } }
/// <summary> /// Returns if this state qualifies as a goal state. /// Checks that all items in the goal match the current state. If an item /// does not exist in the state, it expands it to contain that item's state. /// </summary> public bool IsGoalState(IGoal goal, bool returnGoal = true) { var worldGoal = goal as WorldGoal; DebugUtils.Assert(worldGoal != null, "Expected WorldGoal but got " + goal); var isGoal = true; foreach (var targetGoal in worldGoal) { if (!ContainsKey(targetGoal.Key)) { this[targetGoal.Key] = targetGoal.Key.GetState(); } var targetState = this[targetGoal.Key]; if (!targetState.DoConditionsApply(targetGoal.Value)) { isGoal = false; break; } } if (returnGoal) { worldGoal.ReturnSelf(); } return(isGoal); }
private void InitializeBloodFXData() { string path = "Scripts/AI/BloodFXData"; TextAsset textAsset = Resources.Load(path) as TextAsset; if (!textAsset) { DebugUtils.Assert("Can't load BloodFXData script!", true, DebugUtils.AssertType.Info); return; } TextAssetParser textAssetParser = new TextAssetParser(textAsset); for (int i = 0; i < textAssetParser.GetKeysCount(); i++) { Key key = textAssetParser.GetKey(i); if (key.GetName() == "Blunt") { List <string> value = new List <string>(key.GetVariable(0).SValue.Split(new char[] { ';' })); this.m_BloodFXNames.Add(0, value); } else if (key.GetName() == "Sharp") { List <string> value2 = new List <string>(key.GetVariable(0).SValue.Split(new char[] { ';' })); this.m_BloodFXNames.Add(1, value2); } } Resources.UnloadAsset(textAsset); }
public void ReadChars(char[] buffer, uint count) { if ((ulong)(this.m_Pos + count) > (ulong)((long)this.m_Buffer.Length)) { throw new IndexOutOfRangeException(string.Concat(new object[] { "NetworkReader:ReadChars out of range: (", count, ") ", this.ToString() })); } if (this.m_Guard > 0u && this.m_Pos + count > this.m_Guard) { DebugUtils.Assert("Over-reading network buffer!", true, DebugUtils.AssertType.FatalError); } ushort num = 0; while ((uint)num < count) { buffer[(int)num] = (char)this.m_Buffer[(int)(this.m_Pos + (uint)num)]; num += 1; } this.m_Pos += count; }
public GameObject GetPrefab(EntityType type) { GameObject go; DebugUtils.Assert(prefabTable.TryGetValue(type, out go), $"Entity of type {type} not found in prefab table."); return(go); }
private GameObject CreateGameObject(INetObject obj) { GameObject go = null; if (netObjectCreateDict.ContainsKey(obj.NetObjectType)) { go = netObjectCreateDict[obj.NetObjectType](); } else { // This basically says "if the obj doesn't have a creator registered and also doesn't have an assigned // entity type, then that's no good" if (obj.EntityType == EntityType.NOTHING) { DebugUtils.Assert(false, $"No registered creator for net object of type {obj.NetObjectType}."); } go = Game.Instance.EntityObjectFactory.CreateEntityObject(obj.EntityType); } DebugUtils.Assert(go.GetComponent <NetObject>() != null, $"Game object of type {obj.NetObjectType} missing NetObject component. Did you forget to register a child?"); go.GetComponent <NetObject>().SetNetObject(obj); return(go); }
public void SpawnProjecile(Vector3 direction, int projectileMetaId, float speedRate) { SetRotation(direction, true); ProjectileProto proto = null; if (unitProjectiles.ContainsKey(projectileMetaId)) { proto = unitProjectiles[projectileMetaId]; } else { proto = DataManager.GetInstance().projectileProtoData.Find(p => p.ID == projectileMetaId); } if (proto != null) { PlayAnimation(TRIGGER_ATTACK, speedRate); PlayEffect(proto.FireEffect_ResourceId, proto.fire_res_bindpoint, speedRate); } else { DebugUtils.Assert(false, string.Format(" Can't find projectile meta id {0} when solder spawn a projectile", projectileMetaId)); } }
private void SetupHookInWaterPos() { if (!this.m_Hook) { return; } float terrainY = MainLevel.GetTerrainY(this.m_FloatPos); if (terrainY >= this.m_FloatPos.y) { DebugUtils.Assert("[FishingRod:OnEnterState] Float is under terrain!", true, DebugUtils.AssertType.Info); } Vector3 floatPos = this.m_FloatPos; if (this.m_FishTank) { floatPos.y = this.m_FishTank.transform.position.y; } if (floatPos.y < terrainY + 0.2f) { floatPos.y = terrainY + 0.2f; } floatPos.y = Mathf.Min(floatPos.y, this.m_FloatPos.y); this.m_Hook.transform.position = floatPos; this.m_HookInWaterPos = floatPos; }
/// <summary> /// Check for pickup type and set powerup effect /// </summary> /// <param name="other">What are we colliding with? Should only check for player</param> private void OnTriggerEnter(Collider other) { if (!other.gameObject.CompareTag("Player")) { return; } switch (pickupType) { case PickupType.FireRate: IncreaseFireRate(); break; case PickupType.BulletVel: IncreaseBulletVelocity(); break; case PickupType.SpeedBoost: IncreasePlayerSpeed(); break; case PickupType.BulletDmg: IncreaseBulletDmg(); break; default: DebugUtils.Assert(false); break; } _particleManager.CreatePowerupParticleEffects(_xForm.position); _pool.Despawn(transform); }
private void Awake() { if (base.ReplIsOwner()) { Collider component = base.GetComponent <Collider>(); if (component) { component.enabled = false; } Collider[] componentsInChildren = base.GetComponentsInChildren <Collider>(); for (int i = 0; i < componentsInChildren.Length; i++) { componentsInChildren[i].enabled = false; } Renderer[] componentsInChildren2 = base.GetComponentsInChildren <Renderer>(); for (int i = 0; i < componentsInChildren2.Length; i++) { componentsInChildren2[i].enabled = false; } Transform child = base.transform.GetChild(0); if (child != null) { child.gameObject.SetActive(false); } GameObject gameObject = Player.Get().gameObject; DebugUtils.Assert(gameObject, true); this.m_LocalPlayerTransform = gameObject.GetComponent <Transform>(); } this.m_NetTransform = base.GetComponent <Transform>(); }
/// <summary> /// A* forward search for a plan that satisfies the given goal. /// </summary> /// <returns>Returns null if a plan could not be found, or a list of the /// actions that must be performed, in order.</returns> public static Queue <ITransition> Plan( GoapAgent agent, WorldGoal goal) { var worldState = WorldState.Borrow(); worldState[agent] = agent.GetState(); var regressiveSearchGoal = RegressiveSearchWorldGoal.Borrow(goal); DebugUtils.Assert(worldState[agent].ContainsKey("x") && worldState[agent].ContainsKey("y") && worldState[agent].ContainsKey("z"), "Agent's state must contain his position as 'x' and 'y' keys"); var path = AStarSearch.Search(agent, regressiveSearchGoal, worldState, true); worldState.ReturnSelf(); GoapAction.WithContext.ReportLeaks(); State.ReportLeaks(); WorldState.ReportLeaks(); WorldGoal.ReportLeaks(); RegressiveSearchWorldGoal.ReportLeaks(); WorldEffects.ReportLeaks(); return(path); }