private void SetViewModel(IWorldObjectView objectView, WorldObjectType objectType) { IWorldObjectModel objectModel; if (objectType == WorldObjectType.LIGHT) { var lightView = (LightView)objectView; objectModel = new LightModel(); objectModel.LocalCenterPoint = lightView.localCenterPoint; ((ILightModel)objectModel).Intensity = lightView.lightComponent.intensity; ((ILightModel)objectModel).ConeAngle = lightView.lightComponent.spotAngle; } else { var shapeView = (ShapeView)objectView; objectModel = new ShapeModel(); objectModel.LocalCenterPoint = shapeView.localCenterPoint; ((IShapeModel)objectModel).Color = WorldObjectMaterials.Instance.ShapeDefaultColor; } objectModel.Type = objectType; objectModel.Name = objectType.ToString(); objectModel.Position = Vector3.zero; objectModel.Rotation = Quaternion.identity; objectView.Model = objectModel; }
//Gets the closest untaken World Object to a certain point of a certain type public WorldObject GetClosestUntakenWorldObject(Vector3 a_position, WorldObjectType a_type, List <WorldObject> a_discardedWOs) { WorldObject f_closestWO = null; float f_distance = 0; for (int i = 0; i < m_worldObjects.Count; i++) { if (m_worldObjects[i].m_type == a_type && !m_worldObjects[i].m_taken && !a_discardedWOs.Contains(m_worldObjects[i])) { if (f_closestWO != null) { float f_tempDistance = (a_position - m_worldObjects[i].m_position).LengthSquared(); if (f_tempDistance < f_distance) { f_distance = f_tempDistance; f_closestWO = m_worldObjects[i]; } }//if the WO is null it has to be initialized :p else { f_closestWO = m_worldObjects[i]; f_distance = (a_position - m_worldObjects[i].m_position).LengthSquared(); } } } return(f_closestWO); }
public WorldObject(Model a_model, ref Vector3 a_position, Vector3 a_size, WorldObjectType a_type) { m_model = a_model; m_position = a_position; m_type = a_type; m_size = a_size; }
private IWorldObjectView AddViewInstance(WorldObjectType objectType) { var objInstance = _objectPools[objectType].Next(); objInstance.transform.SetParent(_worldObjectContainer); return(objInstance.GetComponent <IWorldObjectView>()); }
// // private IEnumerator DestroyGameObject () // { // yield return new WaitForSeconds (destroyWaitTime); // Destroy (gameObject); // } public virtual void SetStatsDick() { statsDick = new Dictionary <StatsType, float[]> { { StatsType.Health, healthArray } }; // if the defense array has not been set manually in the prefab if (defenseArray.Length == 0) { WorldObjectType thisDefenseType = WorldObjectType.Empty; if (defenseType == WorldObjectType.LightUnit || defenseType == WorldObjectType.HeavyUnit || defenseType == WorldObjectType.Siege) { thisDefenseType = defenseType; } else if (this as Building) { thisDefenseType = WorldObjectType.Building; } if (thisDefenseType != WorldObjectType.Empty) { defenseArray = GameManager.DuplicateArray(GameManager.baseDefenseTypeArraysDick[thisDefenseType]); } } statsDick.Add(StatsType.Defense, defenseArray); if (attackArray.Length > 0) { statsDick.Add(StatsType.Attack, attackArray); } }
public void RenderObject(WorldObjectType objectType, int x, int y, int z, float alpha) { var p = world.isoToWorld(x, y, z) + new Vector2(0, world.currentMapDepth * (world.blockSizeOver2 + world.floorSizeOver2)); var renderer = (worldObjectRenderers[(int)objectType] ?? worldObjectRenderers[(int)WorldObjectType.Missing]); renderer.Render(this, p, z, alpha); }
public MapRespawnRegion(int x, int z, int width, int length, int time, WorldObjectType type, int modelId, int count) : base(x, z, width, length) { this.ModelId = modelId; this.Time = time; this.ObjectType = type; this.Count = count; this.Entities = new List <IEntity>(); }
protected void ChangeWorldObjectTypeStats(int change, WorldObjectType worldObjectType, StatsType statsType, int index) { List <string> worldObjectTypeNameList = GameManager.GetSpeciesWOTList(GetSpecies(), worldObjectType); foreach (string woName in worldObjectTypeNameList) { ChangeWorldObjectStats(change, woName, statsType, index); } }
protected void UpgradeWorldObjectType(WorldObjectType wot, StatsType upgradeStat, int statarrayIndex) { List <string> woNames = GameManager.GetSpeciesWOTList(species, wot); foreach (string woName in woNames) { UpgradeWorldObject(woName, upgradeStat, statarrayIndex); } }
public MapObject(WorldObjectType type, string name, double x, double y, int width, int height) { X = x; Y = y; Width = width; Height = height; Type = type; Name = name; }
private int GetActualIndex(WorldObjectType toGet) { int[] indexes = System.Enum.GetValues(typeof(WorldObjectType)) as int[]; for (int i = 0; i < indexes.Length; i++) { if ((WorldObjectType)indexes[i] == toGet) { return(i); } } return(int.MaxValue); }
protected void UpgradeAllSpeciesWOT(WorldObjectType woType, StatsType statsType, int statsIndex) { List <string> woNamesList = new List <string> (); foreach (Species thisSpecies in GameManager.speciesArray) { woNamesList.AddRange(GameManager.GetSpeciesWOTList(thisSpecies, woType)); } foreach (string woName in woNamesList) { UpgradeWorldObject(woName, statsType, statsIndex); } }
public string GetObjectResPath(WorldObjectType type, byte id) { string fullPath = ""; switch (type) { case WorldObjectType.None: break; case WorldObjectType.Monster: fullPath = resDic[id]; break; } return(fullPath); }
public Item(GameObject item_object, Sprite custom_sprite = null) { this.item_object = item_object; object_type = GetObjectType(item_object); if (custom_sprite == null) { sprite = item_object.GetComponent <SpriteRenderer>().sprite; } else { sprite = custom_sprite; } }
public static void Initiate() { if (!created) { created = true; gravityAngle *= Mathf.Deg2Rad; float gravityMag = Physics.gravity.magnitude; Physics.gravity = new Vector3(0f, -Mathf.Cos(gravityAngle) * gravityMag, -Mathf.Sin(gravityAngle) * gravityMag); // NavMesh.avoidancePredictionTime has the potential to affect the performance a lot NavMesh.avoidancePredictionTime = 4f; playersDick = new Dictionary <Species, Player>(); resGatheringTime = new WaitForSeconds(5); woWaitTime = new WaitForSeconds(1f); mainSpriteDick = new Dictionary <string, Sprite> (); woLayerMask = LayerMask.GetMask(new string[] { "Bunnies", "Deer", "Sheep", "Wolves", "NonPlayer" }); specToArrayIndexDick = new Dictionary <SpecType, int> { { SpecType.Nature, 0 }, { SpecType.Sun, 1 }, { SpecType.Stick, 2 }, { SpecType.Rock, 3 }, { SpecType.Wheel, 4 }, { SpecType.Fire, 5 } }; resourceTypeArraytoDick = new Dictionary <int, ResourceType> { { 0, ResourceType.Gold }, { 1, ResourceType.Wood }, { 2, ResourceType.Unique } }; worldObjectTypeArray = new WorldObjectType[] { WorldObjectType.WorldObject, WorldObjectType.Building, WorldObjectType.Tower, WorldObjectType.Mobtrainer, WorldObjectType.Sentry, WorldObjectType.NonRelatedUnitTrainer, WorldObjectType.SpeciesUnitTrainer, WorldObjectType.StrategicPoint, WorldObjectType.Resource, WorldObjectType.Monument, WorldObjectType.Mobile, WorldObjectType.SentryMob, WorldObjectType.Unit, WorldObjectType.Melee, WorldObjectType.Ranged, WorldObjectType.LightUnit, WorldObjectType.HeavyUnit, WorldObjectType.Siege }; speciesArray = new Species[] { Species.Bunnies, Species.Deer, Species.Sheep, Species.Wolves }; eraOrderDick = new Dictionary <Eras, int> { { Eras.StoneAge, 1 }, { Eras.Classical, 2 }, { Eras.Renaissance, 3 }, { Eras.Industrial, 4 }, { Eras.Information, 5 } }; orderEraDick = new Dictionary <int, Eras> { { 1, Eras.StoneAge }, { 2, Eras.Classical }, { 3, Eras.Renaissance }, { 4, Eras.Industrial }, { 5, Eras.Information } }; attackTypeArray = new AttackType[] { AttackType.Blunt, AttackType.Pierce, AttackType.Crush, AttackType.Incendiary, AttackType.Psychological }; attackTypeDickToArray = new Dictionary <AttackType, int> { { AttackType.Blunt, 0 }, { AttackType.Pierce, 1 }, { AttackType.Crush, 2 }, { AttackType.Incendiary, 3 }, { AttackType.Psychological, 4 } }; baseStatsDick = new Dictionary <string, Dictionary <StatsType, float[]> >(); newEraUpgradesDick = new Dictionary <string, Dictionary <Eras, Dictionary <StatsType, List <float[]> > > > (); baseDefenseTypeArraysDick = new Dictionary <WorldObjectType, float[]> { { WorldObjectType.LightUnit, new float[] { 0.1f, -0.4f, 0f, -0.5f, -0.2f } }, { WorldObjectType.HeavyUnit, new float[] { 0.6f, 0.1f, 0.3f, -0.5f, -1f } }, { WorldObjectType.Siege, new float[] { -0.1f, 0.99f, 0f, -0.5f, 1f } }, { WorldObjectType.Building, new float[] { 0.4f, 0.99f, -0.8f, -0.5f, 1f } } }; animationEventsArray = new Dictionary <string, List <AnimationEventMethod> > (); } }
public override void OnEnable() { base.OnEnable(); completeIcon = AssetDatabase.LoadAssetAtPath("Assets/TotalAI/Editor/Images/build.png", typeof(Texture2D)) as Texture2D; damageIcon = AssetDatabase.LoadAssetAtPath("Assets/TotalAI/Editor/Images/damage.png", typeof(Texture2D)) as Texture2D; statesIcon = AssetDatabase.LoadAssetAtPath("Assets/TotalAI/Editor/Images/states.png", typeof(Texture2D)) as Texture2D; skinMappingsIcon = AssetDatabase.LoadAssetAtPath("Assets/TotalAI/Editor/Images/inventory.png", typeof(Texture2D)) as Texture2D; skinPrefabsIcon = AssetDatabase.LoadAssetAtPath("Assets/TotalAI/Editor/Images/change.png", typeof(Texture2D)) as Texture2D; recipesIcon = AssetDatabase.LoadAssetAtPath("Assets/TotalAI/Editor/Images/stack.png", typeof(Texture2D)) as Texture2D; worldObjectType = (WorldObjectType)target; lineHeight = EditorGUIUtility.singleLineHeight; serializedPrefabs = serializedObject.FindProperty("skinPrefabMappings"); prefabList = new ReorderableList(serializedObject, serializedPrefabs, true, true, true, true) { drawElementBackgroundCallback = EditorUtilities.DrawReordableListBackground, drawElementCallback = DrawPrefabListItems, elementHeightCallback = PrefabHeight, onAddCallback = OnAddPrefab, headerHeight = 1 }; serializedStates = serializedObject.FindProperty("states"); stateList = new ReorderableList(serializedObject, serializedStates, true, true, true, true) { drawElementBackgroundCallback = EditorUtilities.DrawReordableListBackground, drawElementCallback = DrawStateListItems, onAddCallback = OnAddState, elementHeightCallback = StateHeight, drawHeaderCallback = DrawStateHeader, }; serializedOutputChanges = serializedObject.FindProperty("statesOutputChanges"); outputChangeList = new ReorderableList(serializedObject, serializedOutputChanges, true, true, true, true) { drawElementBackgroundCallback = EditorUtilities.DrawReordableListBackground, drawElementCallback = DrawOutputChangeListItems, onAddCallback = OnAddOutputChange, elementHeightCallback = OutputChangeHeight, drawHeaderCallback = DrawOutputChangeHeader, }; }
private void SelectWorldObject(WorldObjectType worldObjectType, int number) { if (craft.Status == CraftStatus.Ready) { craft.Status = CraftStatus.Out; craft.Location = craft.Base.Location; } else { craft.RemoveWaypoint(); } craft.IsPatrolling = false; craft.Destination = new Destination { WorldObjectType = worldObjectType, Number = number }; }
private void SpawnItem(WorldObjectType objectType) { iterationsCountSinceLastItemSpawn[objectType]++; var iterationsCount = iterationsCountSinceLastItemSpawn[objectType]; if (iterationsCount < Config.ItemSpawnIterationDelay[objectType]) { return; } iterationsCountSinceLastItemSpawn[objectType] = 0; if (Map.PlacedObjectsCounts[objectType] >= Config.MaxItemsCountOnMap[objectType]) { return; } IWorldMapObject ObjFactory(Point pos) => WorldObjFactory.GetWorldObj(objectType, pos); mapFiller.PlaceObject(ObjFactory, 1, Map); }
public static IWorldMapObject GetWorldObj(WorldObjectType objectType, Point position) { switch (objectType) { case WorldObjectType.Poison: return(new Poison(position)); case WorldObjectType.Wall: return(new Wall(position)); case WorldObjectType.Food: return(new Food(position)); case WorldObjectType.Empty: return(new Empty(position)); } return(null); }
public override void Init() { //instantiate Queues for each Type in WorldObjectType enum objects = new Queue <WorldObject> [WorldObjectType.GetNames(typeof(WorldObjectType)).Length]; for (int i = 0; i < objects.Length; i++) { objects[i] = new Queue <WorldObject>(); } //auto sort prefabs array to make sure the indexes match the WorldObjectType enum WorldObject[] tempPrefabs = new WorldObject[prefabs.Length]; for (int i = 0; i < tempPrefabs.Length; i++) { int newIndex = (int)prefabs[i].objectType; tempPrefabs[newIndex] = prefabs[i]; } prefabs = tempPrefabs; }
protected override void Parse(BigEndianReader reader) { reader.ReadByte(); // ID reader.ReadInt16(); // Size place holder _DataType = (WorldObjectType)reader.ReadByte(); _Serial = reader.ReadUInt32(); _ObjectID = reader.ReadInt16(); _ObjectIDOffset = reader.ReadByte(); _Amount = reader.ReadInt16(); reader.ReadInt16(); // Amount again? _X = reader.ReadInt16(); _Y = reader.ReadInt16(); _Z = reader.ReadSByte(); _LightLevel = reader.ReadByte(); _Hue = reader.ReadInt16(); byte flags = reader.ReadByte(); if ((flags & 0x20) > 0) { _HasProperties = true; } else { _HasProperties = false; } if ((flags & 0x80) > 0) { _IsVisible = true; } else { _IsVisible = false; } _Access = (WorldObjectAccess)reader.ReadInt16(); }
///<summary> ///Returns a world object of a specific type on a specific area! ///</summary> public WorldObject GetWorldObject(ref Rectangle a_buildArea, WorldObjectType a_type) { foreach (WorldObject worldObject in m_worldObjects) { Rectangle f_woArea = MathGameHelper.GetAreaRectangle(ref worldObject.m_position, ref worldObject.m_size); if (MathGameHelper.RectanglesIntersects(ref a_buildArea, ref f_woArea) && a_type == worldObject.m_type) { if (worldObject.m_type == WorldObjectType.SoL) { if ((worldObject as SoL).m_taken) { return(null); } } return(worldObject); } } return(null); }
void InitializePool(uint size, WorldObjectType objectType) { string resourcePath = null; switch (objectType) { case WorldObjectType.SPHERE: resourcePath = "Prefabs/WorldObjects/SphereWO"; break; case WorldObjectType.CUBE: resourcePath = "Prefabs/WorldObjects/CubeWO"; break; case WorldObjectType.CYLINDER: resourcePath = "Prefabs/WorldObjects/CylinderWO"; break; case WorldObjectType.LIGHT: resourcePath = "Prefabs/WorldObjects/LightWO"; break; default: throw new ArgumentException("Cannot initialize pool for unknown type:" + objectType); } var objectName = objectType.ToString(); var template = Resources.Load <GameObject>(resourcePath); var container = new GameObject(string.Format("{0} Pool", objectName)).transform; container.transform.position = Vector3.down * 20f; container.transform.SetParent(this.transform); container.gameObject.SetActive(false); _objectPools[objectType] = new ObjectPool(size, template, container, objectName); }
public WorldObject(WorldObjectType type, Position position, char skin) { this.Skin = skin; this.Position = position; this.Type = type; }
protected override void Parse( BigEndianReader reader ) { reader.ReadByte(); // ID reader.ReadInt16(); // Size place holder _DataType = (WorldObjectType) reader.ReadByte(); _Serial = reader.ReadUInt32(); _ObjectID = reader.ReadInt16(); _ObjectIDOffset = reader.ReadByte(); _Amount = reader.ReadInt16(); reader.ReadInt16(); // Amount again? _X = reader.ReadInt16(); _Y = reader.ReadInt16(); _Z = reader.ReadSByte(); _LightLevel = reader.ReadByte(); _Hue = reader.ReadInt16(); byte flags = reader.ReadByte(); if ( ( flags & 0x20 ) > 0 ) _HasProperties = true; else _HasProperties = false; if ( ( flags & 0x80 ) > 0 ) _IsVisible = true; else _IsVisible = false; _Access = (WorldObjectAccess) reader.ReadInt16(); }
protected WorldObject(WorldObjectType type) { worldType = type; }
public static List <string> GetSpeciesWOTList(Species species, WorldObjectType wot) { return(gameObjectList.speciesWOTDick [species] [wot]); }
public void setResearch(string researchName, WorldObjectType type, string researchEffedWO, string researchEffedStat, float researchValueToTakeEff, float buildTime, int doughCost, int sugarCost, int chocolateCost, int maxTimes, Sprite image) { if (Set) return; Name = researchName; Type = type; EffectedWorldObject = researchEffedWO; EffectedStat = researchEffedStat; ValueToTakeEffect = researchValueToTakeEff; BuildTime = buildTime; DoughCost = doughCost; SugarCost = sugarCost; ChocolateCost = chocolateCost; MaxTimes = maxTimes; Image = image; TimesResearched = 0; Enabled = true; Set = true; }
public void setOrderBarState(WorldObjectType objectType) { this.orderBarState = objectType; }
public Player(WorldObjectType type, Position position, char skin) : base(type, position, skin) { }
protected virtual void Start() { this.player = transform.root.GetComponentInChildren<Player>(); this.cost = this.sellValue = 0; this.hitPoints = this.maxHitPoints = 0; this.type = WorldObjectType.None; selectionBounds = ResourceManager.InvalidBounds; CalculateBounds(); }
// Use this for initialization void Start() { player = transform.root.GetComponent< Player >(); buildAreaHeight = Screen.height - RESOURCE_BAR_HEIGHT - SELECTION_NAME_HEIGHT - 2 * BUTTON_SPACING; resourceValues = new Dictionary< ResourceType, int >(); resourceLimits = new Dictionary< ResourceType, int >(); orderBarState = WorldObjectType.None; SetupResourceIcons(); SetCursorState(CursorState.Select); ResourceManager.StoreSelectBoxItems(this.selectBoxSkin); }
public int this[WorldObjectType itemType] { get => GetOrSetItemValue(itemType);
public void RemoveViewInstance(WorldObjectType objectType, GameObject worldObject) { _objectPools[objectType].Store(worldObject); }
public override void OnInspectorGUI() { serializedObject.Update(); Texture2D whiteTexture = Texture2D.whiteTexture; GUIStyle style = new GUIStyle("box") { margin = new RectOffset(0, 0, 0, 0), padding = new RectOffset(0, 0, 0, 0) }; style.normal.background = whiteTexture; Color defaultColor = GUI.backgroundColor; GUI.backgroundColor = EditorUtilities.L15; GUILayout.BeginVertical(style); GUI.backgroundColor = defaultColor; Color sectionColor = EditorUtilities.L2; //UnityEngine.Object entityType = serializedObject.FindProperty("entityType").objectReferenceValue; GUILayout.Space(15); Type type = EntityType.GetEntityType(entity); if (entity.entityType == null) { EditorGUILayout.HelpBox(ObjectNames.NicifyVariableName(type.Name) + " must be specified.", MessageType.Error); GUILayout.Space(5); } EditorGUI.indentLevel++; EntityType entityType = (EntityType)EditorGUILayout.ObjectField("World Object Type", entity.entityType, typeof(WorldObjectType), false); serializedObject.FindProperty("entityType").objectReferenceValue = entityType; EditorGUILayout.PropertyField(serializedObject.FindProperty("prefabVariantIndex")); EditorGUI.indentLevel--; GUILayout.Space(10); WorldObjectType worldObjectType = entity.entityType as WorldObjectType; if (entity.entityType != null && worldObject != null && worldObjectType.states != null && worldObjectType.states.Count > 0) { EditorGUI.indentLevel++; List <string> stateNames = worldObjectType.StateNames(); string startStateName = serializedObject.FindProperty("startState").FindPropertyRelative("name").stringValue; int currentSelection = stateNames.IndexOf(startStateName); int selectedIndex = EditorGUILayout.Popup("Start State", currentSelection, stateNames.ToArray()); if (currentSelection != selectedIndex) { worldObject.startState = worldObjectType.states.Find(x => x.name == stateNames[selectedIndex]); EditorUtility.SetDirty(worldObject); } EditorGUILayout.PropertyField(serializedObject.FindProperty("runOutputChangesOnStart")); EditorGUILayout.PropertyField(serializedObject.FindProperty("startCompletePoints")); EditorGUI.indentLevel--; GUILayout.Space(10); } if (Application.isPlaying && entity.gameObject.activeInHierarchy && entity.entityType != null) { if (worldObject.tags != null && worldObject.tags.Count > 0) { EditorGUI.indentLevel++; EditorGUI.BeginDisabledGroup(true); EditorGUILayout.LabelField("Tags", string.Join(", ", worldObject.tags.Select(x => x.Key.name)), new GUIStyle("boldLabel")); EditorGUI.EndDisabledGroup(); EditorGUI.indentLevel--; } if (worldObject.inEntityInventory) { EditorGUI.indentLevel++; EditorGUI.BeginDisabledGroup(true); EditorGUILayout.LabelField("In Inventory Of", worldObject.inEntityInventory.name, new GUIStyle("boldLabel")); EditorGUI.EndDisabledGroup(); EditorGUI.indentLevel--; } if (worldObject.worldObjectType.states != null && worldObject.worldObjectType.states.Count > 0 && worldObject.currentState != null) { EditorGUI.indentLevel++; EditorGUI.BeginDisabledGroup(true); EditorGUILayout.LabelField("Current State", worldObject.currentState.name, new GUIStyle("boldLabel")); EditorGUI.EndDisabledGroup(); EditorGUI.indentLevel--; } if (worldObject.worldObjectType.completeType != WorldObjectType.CompleteType.None) { EditorGUI.indentLevel++; EditorGUI.BeginDisabledGroup(true); EditorGUILayout.LabelField("Complete Points", worldObject.completePoints + " / " + worldObject.worldObjectType.pointsToComplete, new GUIStyle("boldLabel")); EditorGUI.EndDisabledGroup(); EditorGUI.indentLevel--; } if (worldObject.worldObjectType.canBeDamaged) { EditorGUI.indentLevel++; EditorGUI.BeginDisabledGroup(true); EditorGUILayout.LabelField("Damage Points", worldObject.damage + " / " + worldObject.worldObjectType.damageToDestroy, new GUIStyle("boldLabel")); EditorGUI.EndDisabledGroup(); EditorGUI.indentLevel--; } } if (entity.entityType == null) { GUILayout.BeginVertical("helpbox"); bool allowCreate = true; EditorGUI.indentLevel++; GUILayout.Space(8); EditorGUILayout.LabelField("Quick Create WorldObjectType", new GUIStyle("boldLabel")); GUILayout.Space(8); if (!Directory.Exists(newWorldObjectTypeDir)) { allowCreate = false; GUILayout.Space(5); EditorGUILayout.HelpBox("World Object Type Directory does not exist.", MessageType.Error); GUILayout.Space(5); } if (string.IsNullOrEmpty(newWorldObjectTypeDir) && totalAIManager != null && totalAIManager.settings != null) { newWorldObjectTypeDir = totalAIManager.settings.scriptableObjectsDirectory + "/WorldObjectTypes"; } newWorldObjectTypeDir = EditorGUILayout.TextField("World Object Type Directory", newWorldObjectTypeDir); if (!Directory.Exists(newWorldObjectPrefabDir)) { allowCreate = false; GUILayout.Space(5); EditorGUILayout.HelpBox("World Object Prefab Directory does not exist.", MessageType.Error); GUILayout.Space(5); } if (string.IsNullOrEmpty(newWorldObjectPrefabDir) && totalAIManager != null && totalAIManager.settings != null) { newWorldObjectPrefabDir = totalAIManager.settings.prefabsDirectory + "/WorldObjects"; } newWorldObjectPrefabDir = EditorGUILayout.TextField("World Object Prefab Directory", newWorldObjectPrefabDir); if (string.IsNullOrEmpty(newWorldObjectTypeName)) { newWorldObjectTypeName = worldObject.name; } string potentialPath = newWorldObjectTypeDir + "/" + newWorldObjectTypeName + ".asset"; if (AssetDatabase.AssetPathToGUID(potentialPath) != null && AssetDatabase.AssetPathToGUID(potentialPath) != "" && AssetDatabase.LoadAssetAtPath <UnityEngine.Object>(potentialPath) != null) { allowCreate = false; GUILayout.Space(5); EditorGUILayout.HelpBox("World Object Type of that name and that directory already exists: '" + potentialPath + "'", MessageType.Error); GUILayout.Space(5); } if (Application.isPlaying) { allowCreate = false; } newWorldObjectTypeName = EditorGUILayout.TextField("Name", newWorldObjectTypeName); //selectedNewTypeIndex = EditorGUILayout.Popup("World Object Type Template", selectedNewTypeIndex, newTypeOptions); GUILayout.BeginHorizontal(new GUIStyle("label") { margin = new RectOffset((int)EditorGUIUtility.labelWidth, 0, 10, 0) }); EditorGUI.BeginDisabledGroup(!allowCreate); bool create = GUILayout.Button("Create New World Object Type", new GUIStyle("button") { padding = new RectOffset(8, 8, 8, 8) }, GUILayout.Width(240f)); EditorGUI.EndDisabledGroup(); GUILayout.EndHorizontal(); EditorGUI.indentLevel--; GUILayout.Space(10); GUILayout.EndVertical(); // TODO: Move this into WorldObjecTypeTemplate SO if (create) { // Makes sure layer is correct if (worldObject.gameObject.layer != LayerMask.NameToLayer("WorldObject")) { SetLayerRecursively(worldObject, worldObject.gameObject, LayerMask.NameToLayer("WorldObject"), false); Debug.Log("WorldObject's GameObject's layer and all children's layers set to 'WorldObject'."); } // Make sure has a collider if (totalAIManager.settings.for2D) { Collider2D collider2D = worldObject.GetComponent <Collider2D>(); if (collider2D == null) { worldObject.gameObject.AddComponent <Collider2D>(); Debug.Log("Collider2D added to WorldObject's GameObject."); } } else { Collider collider = worldObject.GetComponent <Collider>(); if (collider == null) { worldObject.gameObject.AddComponent <BoxCollider>(); Debug.Log("BoxCollider added to WorldObject's GameObject."); } } if (!Directory.Exists(newWorldObjectTypeDir)) { Debug.LogError("Directory '" + newWorldObjectTypeDir + "' does not exist. Please fix."); return; } WorldObjectType newWorldObjectType = CreateInstance <WorldObjectType>(); string fullPath = newWorldObjectTypeDir + "/" + newWorldObjectTypeName + ".asset"; fullPath = AssetDatabase.GenerateUniqueAssetPath(fullPath); AssetDatabase.CreateAsset(newWorldObjectType, fullPath); AssetDatabase.SaveAssets(); AssetDatabase.Refresh(); newWorldObjectType = AssetDatabase.LoadAssetAtPath <WorldObjectType>(fullPath); serializedObject.FindProperty("entityType").objectReferenceValue = newWorldObjectType; serializedObject.ApplyModifiedProperties(); GameObject prefab; GameObject transformMappingGO; GameObject transformMappingPrefab; if (!PrefabUtility.IsPartOfAnyPrefab(worldObject.gameObject)) { Debug.Log("World Object is NOT a prefab - Creating Prefab."); if (!Directory.Exists(newWorldObjectPrefabDir)) { Debug.LogError("Directory '" + newWorldObjectPrefabDir + "' does not exist. Unable to create WorldObject Prefab."); return; } string rootPath = newWorldObjectPrefabDir; string guid = AssetDatabase.CreateFolder(rootPath, newWorldObjectTypeName); string newPath = AssetDatabase.GUIDToAssetPath(guid) + "/" + newWorldObjectTypeName + ".prefab"; // Make sure the file name is unique, in case an existing Prefab has the same name. newPath = AssetDatabase.GenerateUniqueAssetPath(newPath); // Create the new Prefab. prefab = PrefabUtility.SaveAsPrefabAssetAndConnect(worldObject.gameObject, newPath, InteractionMode.UserAction); prefab.transform.position = Vector3.zero; Debug.Log("Prefab created at: " + newPath); // Create an empty GO and make it a prefab for TransformMappings string transformMappingPrefabName = newWorldObjectTypeName + "TransformMapping"; transformMappingGO = new GameObject(transformMappingPrefabName); newPath = AssetDatabase.GUIDToAssetPath(guid) + "/" + transformMappingPrefabName + ".prefab"; newPath = AssetDatabase.GenerateUniqueAssetPath(newPath); transformMappingPrefab = PrefabUtility.SaveAsPrefabAssetAndConnect(transformMappingGO, newPath, InteractionMode.UserAction); transformMappingPrefab.transform.position = Vector3.zero; DestroyImmediate(transformMappingGO); Debug.Log("TransformMapping Prefab created at: " + newPath); } else { Debug.Log("World Object is already a prefab."); string prefabPath = PrefabUtility.GetPrefabAssetPathOfNearestInstanceRoot(worldObject.gameObject); prefab = AssetDatabase.LoadAssetAtPath <GameObject>(prefabPath); } // Grab prefab and set it as the first prefabVariant newWorldObjectType.prefabVariants = new List <GameObject> { prefab }; // Set defaultInventory newWorldObjectType.defaultInventoryType = totalAIManager.settings.defaultInventoryType; EditorUtility.SetDirty(newWorldObjectType); AssetDatabase.SaveAssets(); AssetDatabase.Refresh(); } } base.OnInspectorGUI(); GUILayout.EndVertical(); serializedObject.ApplyModifiedProperties(); Repaint(); }
public MapObject(WorldObjectType type, double x, double y, int width, int height) : this(type, "", x, y, width, height) { }
public MapObject(WorldObjectType type, double x, double y) : this(type, "", x, y, 10, 10) { }