/// <summary> /// Updates the creature status. /// </summary> /// <param name="_object">_object.</param> private static void UpdateStatus(ReferenceGroupObject _object) { if (_object == null) { return; } _object.Status.HasCreatureController = false; _object.Status.HasCreatureAdapter = false; _object.Status.HasHome = false; _object.Status.HasMissionOutpost = false; _object.Status.HasMissionEscort = false; _object.Status.HasMissionPatrol = false; _object.Status.isActiveAndEnabled = false; _object.Status.isActiveInHierarchy = false; _object.Status.isPrefab = false; if (_object.ReferenceGameObject != null) { if (_object.EntityCreature != null) { _object.Status.HasCreatureController = true; if (_object.EntityCreature.isActiveAndEnabled) { _object.Status.isActiveAndEnabled = true; } if (_object.EntityCreature.Creature.Essentials.TargetReady()) { _object.Status.HasHome = true; } if (_object.EntityCreature.Creature.Missions.Outpost.TargetReady()) { _object.Status.HasMissionOutpost = true; } if (_object.EntityCreature.Creature.Missions.Escort.TargetReady()) { _object.Status.HasMissionEscort = true; } if (_object.EntityCreature.Creature.Missions.Patrol.TargetReady()) { _object.Status.HasMissionPatrol = true; } } if (_object.ReferenceGameObject.activeInHierarchy) { _object.Status.isActiveInHierarchy = true; } else if (EditorTools.IsPrefab(_object.ReferenceGameObject)) // Is a prefab { _object.Status.isPrefab = true; } } }
private static void DrawReferenceGroupList(ICECreatureRegister _register, List <ReferenceGroupObject> _list) { for (int _index = 0; _index < _list.Count; _index++) { ReferenceGroupObject _group = _list[_index]; UpdateStatus(_group); if (_group != null && _group.ReferenceGameObject != null) { ICEEditorStyle.SplitterByIndent(EditorGUI.indentLevel); ICEEditorLayout.BeginHorizontal(); EditorGUI.BeginDisabledGroup(_group.Enabled == false); _group.Foldout = EditorGUILayout.Foldout(_group.Foldout, GetTitleText(_group), ICEEditorStyle.Foldout); GUILayout.FlexibleSpace(); DrawEntityType(_group); EditorGUI.EndDisabledGroup(); if (ICEEditorLayout.ListUpDownButtons <ReferenceGroupObject>(_list, _index)) { return; } GUILayout.Space(5); EditorGUI.BeginDisabledGroup(_group.Enabled == false); EditorGUI.BeginDisabledGroup(_group.EntityComponent == null); _group.Break = ICEEditorLayout.CheckButtonMiddle("BREAK", "Deactivates all entity components", _group.Break); EditorGUI.EndDisabledGroup(); _group.UseSoftRespawn = ICEEditorLayout.CheckButtonMiddle("RECYCLE", "Allows the reuse of suspended objects without new instantiations", _group.UseSoftRespawn); EditorGUI.BeginDisabledGroup(_register.UsePoolManagement == false); _group.PoolManagementEnabled = ICEEditorLayout.CheckButtonMiddle("POOL", "Activates Pool Management", _group.PoolManagementEnabled); EditorGUI.EndDisabledGroup(); EditorGUI.EndDisabledGroup(); _group.Enabled = ICEEditorLayout.EnableButton("Enables/Disables the group", _group.Enabled); if (ICEEditorLayout.ListDeleteButtonMini <ReferenceGroupObject>(_list, _group, "Removes this reference group.")) { return; } ICEEditorLayout.EndHorizontal(Info.REGISTER_REFERENCE_OBJECT_GROUP); DrawReferenceGroup(_register, _group); } else { _list.RemoveAt(_index); --_index; } } }
private static string GetTitleText(ReferenceGroupObject _group) { string _suspended = (_group.UseSoftRespawn ? "/" + _group.SuspendedObjects.Count :""); string _amount = ""; if (_group.PoolManagementEnabled) { _amount = " [" + _group.ActiveObjects.Count + _suspended + " of " + _group.MaxCoexistingObjects + "]"; } else { _amount = " [" + _group.ActiveObjects.Count + _suspended + "]"; } return(_group.Name + " " + (EditorTools.IsPrefab(_group.ReferenceGameObject)?"(PREFAB)":"(SCENE)") + _amount); }
private static void DrawEntityType(ReferenceGroupObject _obj) { GUI.backgroundColor = Color.cyan; if (_obj.ReferenceGameObject.GetComponent <ICECreatureEntity>() != null) { ICECreatureEntity _entity = _obj.ReferenceGameObject.GetComponent <ICECreatureEntity>(); GUILayout.Label(new GUIContent(_entity.EntityType.ToString(), "")); } else { GUILayout.Label(new GUIContent("undefined", "")); } GUI.backgroundColor = ICEEditorLayout.DefaultBackgroundColor; GUILayout.Space(10); }
public static void QuickSelectionPopup(string _title, ICECreatureEntity _entity) { ICECreatureRegister _register = ICECreatureRegister.Instance; if (_register == null) { } else { ICEEditorLayout.BeginHorizontal(); int _new_index = Popups.QuickSelectionPopup(_title, QuickSelectIndex); if (_register.ReferenceGroupObjects.Count > 0) { int _own_index = CreatureRegister.GetReferenceIndexByName(_entity.name); if (_new_index != _own_index) { QuickSelectIndex = _new_index; QuickSelectGroup = _register.ReferenceGroupObjects[QuickSelectIndex]; } if (ICEEditorLayout.DebugButton("SELECT", "Activates the displayed GameObject. You can use this funtion to switch between your objects.") && _new_index < _register.ReferenceGroupObjects.Count) { if (_entity != null) { QuickSelectIndex = CreatureRegister.GetReferenceIndexByName(_entity.name); } Selection.activeGameObject = _register.ReferenceGroupObjects[_new_index].ReferenceGameObject; } } else { if (ICEEditorLayout.DebugButton("UPDATE", "Updates the register by scanning the scene for relevant objects")) { _register.UpdateReferences(); } } if (ICEEditorLayout.DebugButton("REGISTER", "Switches the focus to the Creature Register")) { Selection.activeGameObject = _register.gameObject; } if (QuickSelectGroup == null || QuickSelectGroup.EntityType != _entity.EntityType) { EditorGUI.BeginDisabledGroup(true); ICEEditorLayout.DebugButton("COPY", "Copys the settings from the selected entity to this one. Both entities must be from the same type!"); EditorGUI.EndDisabledGroup(); } else { if (ICEEditorLayout.DebugButton("COPY", "Copies the settings from the selected entity to this one. Both entities must be from the same type!")) { string _warning = "Please note, this function copies the settings from the selected entity (" + QuickSelectGroup.Name + ") to this one (" + _entity.name + "). This overwrites all settings " + "of this entity. Are you sure you want to do that? \n\n" + "Press COPY to continue or CANCEL to abort."; if (EditorUtility.DisplayDialog("Copy Message", _warning, "COPY", "CANCEL")) { UnityEditorInternal.ComponentUtility.CopyComponent(QuickSelectGroup.EntityComponent); UnityEditorInternal.ComponentUtility.PasteComponentValues(_entity); } } } ICEEditorLayout.EndHorizontal(Info.ENTITY_QUICK_SELECTION); } }
// PHOTON NETWORK public void OnJoinedRoom() { if (PhotonNetwork.isMasterClient) { m_Register.InitialSpawn(); } if (PhotonNetwork.isMasterClient) { PhotonNetwork.room.maxPlayers = MaxPlayersPerRoom; } // TODO: use PhotonNetwork.LoadLevel to load level while automatically pausing network queue // ("call this in OnJoinedRoom to make sure no cached RPCs are fired in the wrong scene") // also, get level from room properties / master // sent as RPC instead of in 'OnPhotonPlayerConnected' because the // MasterClient does not run the latter for itself + we don't want // to do the request on all clients //if(FindObjectOfType<vp_MPMaster>()) // in rare cases there might not be a vp_MPMaster, for example: a chat lobby // photonView.RPC("RequestInitialSpawnInfo", PhotonTargets.MasterClient, PhotonNetwork.player, 0, name); ICEWorldInfo.IsMasterClient = PhotonNetwork.isMasterClient; if (UseCreatePlayer) { // gets the refrence group of your selected reference player ReferenceGroupObject _group = m_Register.GetGroupByName(ReferencePlayerName); if (_group != null) { _group.MaxCoexistingObjects = MaxPlayersPerRoom; //GameObject _player = _group.Spawn(); Vector3 position = _group.GetSpawnPosition(); GameObject _player = PhotonNetwork.Instantiate(ReferencePlayerName, position, Quaternion.identity, 0); if (_player != null) { if (UseRenamingPlayer && !string.IsNullOrEmpty(PlayerName)) { _player.name = PlayerName; } if (UsePlayerCamera && PlayerCamera != null && !string.IsNullOrEmpty(PlayerCameraAssignMethod)) { /* * // Your Camara script should contain something like this to assign the created player as * // target for your camera ... * public void AssignCameraTarget( GameObject _object ) * { * if( _object == null ) * return; * * Target = _object.transform; * } */ PlayerCamera.SendMessageUpwards(PlayerCameraAssignMethod, _player, SendMessageOptions.DontRequireReceiver); } } } } m_Register.NetworkConnectedAndReady = true; Debug.Log("OnJoinedRoom() called by PUN. Now this client is in a room. From here on, your game would be running. For reference, all callbacks are listed in enum: PhotonNetworkingMessage"); }
private static void DrawFlags(ReferenceGroupObject _object) { string[] _flags = new string[10]; // CC controlled if (_object.Status.HasCreatureController) { _flags[0] = "icons/cc_1"; } else if (_object.Status.HasCreatureAdapter) { _flags[0] = "icons/failed"; } else { _flags[0] = "icons/failed"; } if (_object.Status.HasHome) { _flags[1] = "icons/home_ready"; } else { _flags[1] = "icons/home_failed"; } if (_object.Status.HasMissionOutpost) { _flags[2] = "icons/cc_1"; } else { _flags[2] = "icons/failed"; } if (_object.Status.HasMissionEscort) { _flags[3] = "icons/cc_1"; } else { _flags[3] = "icons/failed"; } if (_object.Status.HasMissionPatrol) { _flags[4] = "icons/cc_1"; } else { _flags[4] = "icons/failed"; } if (_object.Status.isActiveAndEnabled) { _flags[5] = "icons/cc_1"; } else { _flags[5] = "icons/failed"; } if (_object.Status.isActiveInHierarchy) { _flags[6] = "icons/cc_1"; } else { _flags[6] = "icons/failed"; } if (_object.Status.isPrefab) { _flags[7] = "icons/cc_1"; } else { _flags[7] = "icons/failed"; } //EditorGUILayout.Separator(); ICEEditorLayout.DrawLabelIconBar("Status", _flags, 16, 16, 0, 0, 5); }
private static void DrawReferenceGroup(ICECreatureRegister _register, ReferenceGroupObject _obj) { if (_obj == null || _obj.Foldout == false) { return; } EditorGUI.BeginDisabledGroup(_obj.Enabled == false); // BEGIN OBJECT ICEEditorLayout.BeginHorizontal(); _obj.ReferenceGameObject = (GameObject)EditorGUILayout.ObjectField("Reference Object", _obj.ReferenceGameObject, typeof(GameObject), true); EditorGUI.BeginDisabledGroup(_obj.ReferenceGameObject == null); if (_obj.ReferenceGameObject != null) { ICEEditorLayout.ButtonDisplayObject(_obj.ReferenceGameObject.transform.position); } else { ICEEditorLayout.ButtonDisplayObject(Vector3.zero); } ICEEditorLayout.ButtonSelectObject(_obj.ReferenceGameObject, ICEEditorStyle.CMDButtonDouble); //_obj.GroupByTag = ICEEditorLayout.ButtonCheck( "TAG", "Allows to find a group in addition to its name also by its tag.", _obj.GroupByTag, ICEEditorStyle.CMDButtonDouble ); _obj.GroupByTag = false; _obj.UseGroupParent = ICEEditorLayout.CheckButtonMiddle("GROUP", "Assorts instances to the defined Hierarchy Group", _obj.UseGroupParent); EditorGUI.EndDisabledGroup(); ICEEditorLayout.EndHorizontal(Info.REGISTER_REFERENCE_OBJECT); // END OBJECT //_obj.UseHierarchyGroupObject = ICEEditorLayout.Toggle( "Use Hierarchy Group", "", _obj.UseHierarchyGroupObject, Info.REGISTER_REFERENCE_OBJECT_POOL_GROUP_USE ); if (_obj.UseGroupParent) { EditorGUI.indentLevel++; ICEEditorLayout.BeginHorizontal(); _obj.CustomGroupParent = (GameObject)EditorGUILayout.ObjectField("Custom Hierarchy Group", _obj.CustomGroupParent, typeof(GameObject), true); ICEEditorLayout.EndHorizontal(Info.REGISTER_REFERENCE_OBJECT_POOL_GROUP_CUSTOM); if (_obj.CustomGroupParent == null) { EditorGUILayout.HelpBox(Info.REGISTER_REFERENCE_OBJECT_POOL_GROUP_INFO, MessageType.Info); } EditorGUI.indentLevel--; } // BEGIN POOL MANAGEMENT if (_obj.PoolManagementEnabled == true && _register.UsePoolManagement == true) { // PLAYER if (_obj.EntityType == EntityClassType.Player) { _obj.MaxCoexistingObjects = 1; _obj.UseInitialSpawn = true; _obj.InitialSpawnPriority = 0; _obj.UseRandomization = false; _obj.SpawnWaveMin = 1; _obj.SpawnWaveMax = 1; _obj.UseSoftRespawn = true; ICEEditorLayout.MinMaxRandomDefaultSlider("Spawn Interval (min/max)", "", ref _obj.MinSpawnInterval, ref _obj.MaxSpawnInterval, 0, ref _obj.RespawnIntervalMax, 0, 0, 0.25f, 30, Info.REGISTER_REFERENCE_OBJECT_POOL_SPAWN_INTERVAL); if (_obj.MinSpawnInterval > 0 && _obj.ReferenceGameObject != null && _obj.ReferenceGameObject.GetComponentsInChildren <Camera>() != null) { //Debug.Log( "test" ); } } // CREATURES AND OTHER OBJECTS else { ICEEditorLayout.BeginHorizontal(); float _maximum = _obj.MaxCoexistingObjectsMaximum; _obj.MaxCoexistingObjects = (int)ICEEditorLayout.MaxDefaultSlider("Max. Coexistent Objects (" + _obj.ActiveObjectsCount + ")", "Specifies the limit of coexistent objects", _obj.MaxCoexistingObjects, 1, 0, ref _maximum, 25, ""); _obj.MaxCoexistingObjectsMaximum = (int)_maximum; _obj.UseMaxSpawnCycles = ICEEditorLayout.CheckButtonSmall("MAX", "Specifies the total number of objects", _obj.UseMaxSpawnCycles); _obj.UseInitialSpawn = ICEEditorLayout.CheckButtonMiddle("INITIAL", "Spawns all instances on start according to the given priority", _obj.UseInitialSpawn); ICEEditorLayout.EndHorizontal(Info.REGISTER_REFERENCE_OBJECT_POOL_SPAWN_MAX); if (_obj.UseMaxSpawnCycles) { if (_obj.MaxSpawnCycles < _obj.MaxCoexistingObjects) { _obj.MaxSpawnCycles = _obj.MaxCoexistingObjects; } if (_obj.MaxSpawnCyclesMaximum < _obj.MaxCoexistingObjectsMaximum) { _obj.MaxSpawnCyclesMaximum = _obj.MaxCoexistingObjectsMaximum; } float _max_spawn_cycles = _obj.MaxSpawnCyclesMaximum; _obj.MaxSpawnCycles = (int)ICEEditorLayout.MaxDefaultSlider("Max. Spawn Cycles (" + _obj.TotalSpawnCycles + ")", "", _obj.MaxSpawnCycles, 1, _obj.MaxCoexistingObjects, ref _max_spawn_cycles, 25, ""); _obj.MaxSpawnCyclesMaximum = (int)_max_spawn_cycles; } if (_obj.UseInitialSpawn) { EditorGUI.indentLevel++; _obj.InitialSpawnPriority = (int)ICEEditorLayout.DefaultSlider("Initial Spawn Priority", "", _obj.InitialSpawnPriority, 1, 0, 100, 0, Info.REGISTER_REFERENCE_OBJECT_POOL_SPAWN_PRIORITY); EditorGUI.indentLevel--; } ICEEditorLayout.BeginHorizontal(); ICEEditorLayout.MinMaxRandomDefaultSlider("Spawn Interval (min/max)", "", ref _obj.MinSpawnInterval, ref _obj.MaxSpawnInterval, 0, ref _obj.RespawnIntervalMax, 0, 0, 0.25f, 30); _obj.UseSpawnWave = ICEEditorLayout.CheckButton("WAVE", "", _obj.UseSpawnWave, ICEEditorStyle.ButtonMiddle); ICEEditorLayout.EndHorizontal(Info.REGISTER_REFERENCE_OBJECT_POOL_SPAWN_INTERVAL); if (_obj.UseSpawnWave) { EditorGUI.indentLevel++; ICEEditorLayout.MinMaxRandomDefaultSlider("Wave Size (min/max)", "Amount per Wave", ref _obj.SpawnWaveMin, ref _obj.SpawnWaveMax, 1, ref _obj.SpawnWaveMaximum, 1, 5, 30, Info.REGISTER_REFERENCE_OBJECT_POOL_SPAWN_WAVE); EditorGUI.indentLevel--; } EditorGUILayout.Separator(); _obj.UseRandomization = ICEEditorLayout.Toggle("Spawn Randomization", "", _obj.UseRandomization, Info.REGISTER_REFERENCE_OBJECT_POOL_RANDOM_SIZE); if (_obj.UseRandomization) { EditorGUI.indentLevel++; ICEEditorLayout.MinMaxRandomDefaultSlider("Random Size Variance (min/max)", "", ref _obj.RandomSizeMin, ref _obj.RandomSizeMax, -1, 1, 0, 0, 0.025f, 30, Info.REGISTER_REFERENCE_OBJECT_POOL_RANDOM_SIZE_VARIANCE); EditorGUI.indentLevel--; EditorGUILayout.Separator(); } WorldObjectEditor.DrawCullingOptionsObject(_register, _obj.CullingOptions, EditorHeaderType.TOGGLE, Info.REGISTER_REFERENCE_OBJECT_POOL_SPAWN_CONDITIONS, "Spawn Conditions"); } ICEEditorLayout.BeginHorizontal(); ICEEditorLayout.Label("Spawn Areas", false); if (ICEEditorLayout.AddButton("Adds a new spawn point entry")) { _obj.SpawnPoints.Add(new SpawnPointObject()); } ICEEditorLayout.EndHorizontal(Info.REGISTER_REFERENCE_OBJECT_SPAWN_POINTS); EditorGUI.indentLevel++; if (_obj.SpawnPoints.Count == 0) { if (_obj.EntityCreature != null) { _obj.SpawnPoints.Add(new SpawnPointObject(_obj.EntityCreature.Creature.Essentials.Target)); } else if (_obj.ReferenceGameObject != null) { ICECreatureTargetAttribute _target = _obj.ReferenceGameObject.GetComponent <ICECreatureTargetAttribute>(); if (_target != null) { _obj.SpawnPoints.Add(new SpawnPointObject(_target.Target)); } else { _obj.SpawnPoints.Add(new SpawnPointObject(_obj.ReferenceGameObject)); } } } foreach (SpawnPointObject _point in _obj.SpawnPoints) { if (CreatureObjectEditor.DrawSpawnPointObject(_point, _obj.SpawnPoints, EditorHeaderType.FOLDOUT_ENABLED)) { return; } } EditorGUI.indentLevel--; } // END POOL MANAGEMENT EditorGUI.EndDisabledGroup(); EditorGUILayout.Separator(); }
private static void DrawReferenceGroupListCat(ICECreatureRegister _register, string _list_title, ReferenceGroupCategory _cat, ref bool _foldout) { if (_cat == null || _cat.ReferenceGroupObjects == null) { return; } List <ReferenceGroupObject> _list = _cat.ReferenceGroupObjects; EditorGUI.BeginDisabledGroup(_list.Count == 0); // HEADER BEGIN ICEEditorLayout.BeginHorizontal(); _list_title += " (" + _list.Count + ")"; _foldout = ICEEditorLayout.Foldout(_foldout, _list_title, ""); ICEEditorLayout.ListFoldoutButtons <ReferenceGroupObject>(_list); ICEEditorLayout.EndHorizontal(ref _cat.ShowInfoText, ref _cat.InfoText, Info.REGISTER_REFERENCE_CAT); // HEADER END EditorGUI.indentLevel++; if (_foldout) { for (int _index = 0; _index < _list.Count; _index++) { ReferenceGroupObject _group = _list[_index]; UpdateStatus(_group); if (_group != null && _group.ReferenceGameObject != null) { ICEEditorStyle.SplitterByIndent(EditorGUI.indentLevel); ICEEditorLayout.BeginHorizontal(); EditorGUI.BeginDisabledGroup(_group.Enabled == false); _group.Foldout = EditorGUILayout.Foldout(_group.Foldout, GetTitleText(_group), ICEEditorStyle.Foldout); GUILayout.FlexibleSpace(); EditorGUI.BeginDisabledGroup(_group.EntityComponent == null); _group.Break = ICEEditorLayout.CheckButtonMiddle("BREAK", "Deactivates/activates all entity components", _group.Break); EditorGUI.EndDisabledGroup(); _group.UseSoftRespawn = ICEEditorLayout.CheckButtonMiddle("RECYCLE", "Allows the reuse of suspended objects without new instantiations", _group.UseSoftRespawn); EditorGUI.BeginDisabledGroup(_register.UsePoolManagement == false); _group.PoolManagementEnabled = ICEEditorLayout.CheckButtonMiddle("POOL", "Activates Pool Management", _group.PoolManagementEnabled); EditorGUI.EndDisabledGroup(); EditorGUI.EndDisabledGroup(); _group.Enabled = ICEEditorLayout.EnableButton("Enables/Disables the group", _group.Enabled); if (ICEEditorLayout.ListDeleteButtonMini <ReferenceGroupObject>(_register.ReferenceGroupObjects, _group, "Removes this reference group.")) { return; } ICEEditorLayout.EndHorizontal(Info.REGISTER_REFERENCE_OBJECT_GROUP); DrawReferenceGroup(_register, _group); } else { _list.RemoveAt(_index); --_index; } } if (_list.Count > 0) { EditorGUILayout.Separator(); } } EditorGUI.indentLevel--; EditorGUI.EndDisabledGroup(); }