public void UpdateGoal() { //List3D<OCChunk> chunks = _map.GetChunks (); // Since this is probably bogging down the gameplay, switch it to block creation only. //FindGoalBlockPositionInChunks(chunks); Vector3 sourcePos = gameObject.transform.position; Vector3 distanceVec = ((Vector3)GoalBlockPos) - sourcePos; float integrityChange = _goalNameToChangeRatePerSecond["Integrity"] / (distanceVec.magnitude * _distanceAttenuation); integrityChange = integrityChange / 10; UnityEngine.GameObject[] agiArray = UnityEngine.GameObject.FindGameObjectsWithTag("OCAGI"); if (integrityChange > 0.04) { for (int iAGI = 0; iAGI < agiArray.Length; iAGI++) { UnityEngine.GameObject agiObject = agiArray[iAGI]; OpenCog.Embodiment.OCPhysiologicalModel agiPhysModel = agiObject.GetComponent <OpenCog.Embodiment.OCPhysiologicalModel>(); OpenCog.Embodiment.OCPhysiologicalEffect nearHomeEffect = OCPhysiologicalEffect.CreateInstance <OCPhysiologicalEffect>(); nearHomeEffect.CostLevelProp = OpenCog.Embodiment.OCPhysiologicalEffect.CostLevel.NONE; nearHomeEffect.FitnessChange = integrityChange; //UnityEngine.Debug.Log ("Increasing Integrity by '" + integrityChange.ToString() + "'"); agiPhysModel.ProcessPhysiologicalEffect(nearHomeEffect); } } if (GoalBlockPos != Vector3i.zero && _map.GetBlock(GoalBlockPos).IsEmpty()) { OpenCog.Utility.Console.Console console = OpenCog.Utility.Console.Console.Instance; console.AddConsoleEntry("I perceive no more " + _goalBlockType.GetName() + " blocks in my world.", "AGI Robot", OpenCog.Utility.Console.Console.ConsoleEntry.Type.SAY); System.Console.WriteLine(OCLogSymbol.RUNNING + "No more " + _goalBlockType.GetName() + " are reported"); GoalBlockPos = Vector3i.zero; OCAction[] actions = gameObject.GetComponentsInChildren <OCAction>(); foreach (OCAction action in actions) { if (action.EndTarget != null) { action.EndTarget.transform.position = Vector3.zero; } if (action.StartTarget != null) { action.StartTarget.transform.position = Vector3.zero; } } } }
public static void DrawBlockEditor(OCBlock block, OCBlockSet blockSet) { UnityEngine.GUILayout.BeginVertical(UnityEngine.GUI.skin.box); { string name = EditorGUILayout.TextField("Name", block.GetName()); block.SetName(FixNameString(name)); if (block is OCGlassBlock) { OCGlassBlock glass = (OCGlassBlock)block; UnityEngine.GameObject interior = (UnityEngine.GameObject)EditorGUILayout.ObjectField("Interior", glass.GetInterior(), typeof(UnityEngine.GameObject), true, null); glass.SetInterior(interior); } int atlas = BlockEditorUtils.Popup("Atlas", block.AtlasID, blockSet.Atlases); block.AtlasID = atlas; int light = EditorGUILayout.IntField("Light", block.GetLight()); block.SetLight(light); } UnityEngine.GUILayout.EndVertical(); UnityEngine.Texture texture = block.GetTexture(); if (texture != null) { FieldInfo field = DrawFacesList(block, texture); int face = (int)field.GetValue(block); DrawFaceEditor(ref face, block.Atlas, ref atlasMatrix); field.SetValue(block, face); } }
private static bool DrawItem(Rect position, OCBlock block, bool selected, int index) { Rect texturePosition = position; texturePosition.height = texturePosition.width; Rect labelPosition = position; labelPosition.yMin += texturePosition.height; if (selected) { EditorGUIUtils.FillRect(labelPosition, new Color(61 / 255f, 128 / 255f, 223 / 255f)); } if (block != null) { block.DrawPreview(texturePosition); GUI.Label(labelPosition, block.GetName()); } else { EditorGUIUtils.FillRect(texturePosition, Color.grey); GUI.Label(labelPosition, "Null"); } if (Event.current.type == EventType.MouseDown && Event.current.button == 0 && position.Contains(Event.current.mousePosition)) { Event.current.Use(); return(true); } return(false); }
//--------------------------------------------------------------------------- #endregion //--------------------------------------------------------------------------- #region Private Member Functions //--------------------------------------------------------------------------- private void FindGoalBlockPositionInChunks(List3D <OCChunk> chunks) { Vector3 sourcePos = gameObject.transform.position; Vector3 distanceVec = ((Vector3)GoalBlockPos) - sourcePos; // // if(distanceVec.y < -1.0f + 0.5f && distanceVec.y > -1.0f - 0.5f) // if(distanceVec.sqrMagnitude < 2.25f) // { // Debug.Log("We've arrived at our goal TNT block..."); // map.SetBlockAndRecompute(new OCBlockData(), TargetBlockPos); // TargetBlockPos = Vector3i.zero; // // OCAction[] actions = gameObject.GetComponentsInChildren<OCAction>(); // // foreach(OCAction action in actions) // { // action.EndTarget.transform.position = Vector3.zero; // action.StartTarget.transform.position = Vector3.zero; // } // } bool doesGoalExist = false; //distanceVec = new Vector3(1000,1000,1000); for (int cx = chunks.GetMinX(); cx < chunks.GetMaxX(); ++cx) { for (int cy = chunks.GetMinY(); cy < chunks.GetMaxY(); ++cy) { for (int cz = chunks.GetMinZ(); cz < chunks.GetMaxZ(); ++cz) { Vector3i chunkPos = new Vector3i(cx, cy, cz); OCChunk chunk = chunks.SafeGet(chunkPos); if (chunk != null) { for (int z = 0; z < OCChunk.SIZE_Z; z++) { for (int x = 0; x < OCChunk.SIZE_X; x++) { for (int y = 0; y < OCChunk.SIZE_Y; y++) { Vector3i localPos = new Vector3i(x, y, z); OCBlockData blockData = chunk.GetBlock(localPos); Vector3i candidatePos = OCChunk.ToWorldPosition(chunk.GetPosition(), localPos); Vector3 candidateVec = ((Vector3)candidatePos) - sourcePos; if (!blockData.IsEmpty() && blockData.block.GetName() == _goalBlockType.GetName()) { doesGoalExist = true; if (candidateVec.sqrMagnitude < distanceVec.sqrMagnitude) { GoalBlockPos = candidatePos; distanceVec = candidateVec; if (_ShouldMoveTargets) { OCAction[] actions = gameObject.GetComponentsInChildren <OCAction>(); foreach (OCAction action in actions) { action.EndTarget.transform.position = new Vector3(GoalBlockPos.x, GoalBlockPos.y, GoalBlockPos.z); action.StartTarget.transform.position = gameObject.transform.position; } } Debug.Log("We found some " + _goalBlockType.GetName() + " nearby: " + GoalBlockPos + "!"); } } } } } } } } } if (GoalBlockPos != Vector3i.zero && (!doesGoalExist || _map.GetBlock(GoalBlockPos).IsEmpty())) { Debug.Log("No more " + _goalBlockType.GetName() + "... :("); GoalBlockPos = Vector3i.zero; OCAction[] actions = gameObject.GetComponentsInChildren <OCAction>(); foreach (OCAction action in actions) { action.EndTarget.transform.position = Vector3.zero; action.StartTarget.transform.position = Vector3.zero; } } }