// Called when the mouse begins hovering an editable object. internal override void OnBrushEnter(EditableObject target, BrushSettings settings) { base.OnBrushEnter(target, settings); if (target.editMesh == null) { return; } bool refresh = (m_CacheTarget != null && !m_CacheTarget.Equals(target)) || m_CacheTarget == null; if (m_CacheTarget != null && m_CacheTarget.Equals(target.gameObjectAttached)) { var targetMaterials = target.gameObjectAttached.GetMaterials(); refresh = !AreListsEqual(targetMaterials, m_CacheMaterials); } if (refresh) { m_CacheTarget = target; m_CacheMaterials = target.gameObjectAttached.GetMaterials(); m_MeshAttributesContainer = null; currentMeshACIndex = 0; ArrayUtility.Clear(ref m_AvailableMaterialsAsString); m_LikelySupportsTextureBlending = CheckForTextureBlendSupport(target.gameObjectAttached); RebuildCaches(target.editMesh); } if (m_LikelySupportsTextureBlending && (brushColor == null || !brushColor.MatchesAttributes(meshAttributes))) { brushColor = new SplatWeight(SplatWeight.GetChannelMap(meshAttributes)); SetBrushColorWithAttributeIndex(selectedAttributeIndex); } RebuildColorTargets(brushColor, settings.strength); }
public void PrefabsToCells() { if (Prefabs != null && Prefabs.Length > 0) { for (int i = 0; i < Cells.Length; i++) { ArrayUtility.Clear(ref Cells[i].prefab); } // parse prefab names foreach (var go in Prefabs) { string[] tokens = go.name.Split(new char[] { '-' }); int index = int.Parse(tokens[1]); if (tokens.Length == 2) { ArrayUtility.Add(ref Cells[index].prefab, go); } else if (tokens.Length == 3) { ArrayUtility.Add(ref Cells[index].prefab, go); } else { Debug.LogError("parsing of marching squares"); } } } EditorUtility.SetDirty(this); }
private void ResetCustomStyles() { if (customStyles != null) { ArrayUtility.Clear <GUIContent>(ref customStyles); } if (Target.customStyles.Length == 0) { customStyles = new GUIContent[0]; customStyleIndex = -1; return; } customStyles = new GUIContent[Target.customStyles.Length]; for (int i = 0; i < customStyles.Length; i++) { string name = string.IsNullOrEmpty(Target.customStyles[i].name) ? "New Style " + i : Target.customStyles[i].name; Target.customStyles[i].name = name; customStyles[i] = new GUIContent(name); } customStyleIndex = 0; }
public void UpdateGrid() { if (Terrain) { Debug.Log("Updating grid..."); ArrayUtility.Clear <Cell[]>(ref _grid); for (int i = 0; i < GridHeight; i++) { Cell[] list = { }; for (int j = 0; j < GridWidth; j++) { Vector3 xzpos = transform.position + new Vector3(CellWidth * j, 100, CellHeight * i); Ray ray = new Ray(xzpos, Vector3.down); RaycastHit hit; Terrain.Raycast(ray, out hit, 200); Cell c = new Cell(); c.map = this; c.pos = hit.point + new Vector3(0, yOffset, 0); ArrayUtility.Add <Cell>(ref list, c); } ArrayUtility.Add <Cell[]>(ref _grid, list); } Debug.Log("Done updating grid."); } else { Debug.Log("Can't update grid: no terrain given."); } }
public void ClearSelectedNodes() { ArrayUtility.Clear(ref m_selectedNodes); Selection.activeObject = null; onNodesSelected?.Invoke(new Node[0]); }
public void SetSelectedNodes(Node[] nodes) { bool difference = false; UnityEngine.Object[] currentObjects = Selection.objects; if (currentObjects.Length != nodes.Length) { difference = true; } else { for (int i = 0; i < currentObjects.Length; i++) { Object obj = currentObjects[i]; if (!obj.IsTypeOf <Node> ()) { difference = true; break; } Node node = obj as Node; bool alreadySelected = false; for (int j = 0; j < nodes.Length; j++) { if (node == nodes[j]) { alreadySelected = true; break; } } if (!alreadySelected) { difference = true; break; } } } if (difference) { ArrayUtility.Clear(ref m_selectedNodes); ArrayUtility.AddRange(ref m_selectedNodes, nodes); Selection.objects = nodes; // add all new selected nodes at the first entry's in the sortedList. for (int i = 0; i < nodes.Length; i++) { m_lastSelectedNodes.Push(nodes[i]); } onNodesSelected?.Invoke(GetSelectedNodes()); } }
//Clear all elements public bool ClearElements() { if (objects == null || objects.Length == 0) { return(false); } ArrayUtility.Clear(ref objects); return(true); }
void RebuildMaterialCaches() { ArrayUtility.Clear(ref m_AvailableMaterialsAsString); m_CurrentMeshACIndex = 0; m_MainCacheMaterials.Clear(); if (m_MainCacheTarget == null) { return; } m_MeshAttributesContainer = null; m_CurrentMeshACIndex = 0; m_LikelySupportsTextureBlending = CheckForTextureBlendSupport(m_MainCacheTarget.gameObjectAttached); }
public void Cleanup() { allCollectedAssets.Clear(); ArrayUtility.Clear(ref allCollectedAssetsPath); foreach (var bundle in bundles) { bundle.Cleanup(); if (bundle.splits.Count == 0) { var defaultSplit = new BundleSplit(); bundle.splits.Add(defaultSplit); MarkAsDirty(); } } }
public static void ChangeListLenght <T>(ref T[] list, int count, Object recordTarget) where T : new() { if (count < 0) { count = 0; } if (count != list.Length) { Undo.RecordObject(recordTarget, "ChangeListLength"); if (count == 0) { ArrayUtility.Clear(ref list); } while (list.Length < count) { ArrayUtility.Add(ref list, new T()); } while (list.Length > count) { ArrayUtility.RemoveAt(ref list, list.Length - 1); } EditorUtility.SetDirty(recordTarget); } }
private void DrawSelectedType(int id) { if (_selectedType != null) { DrawSelectedTypeHeader(); } GUILayout.Space(10); // Add property if (ColorButton.Draw("Add New Property", CommonColor.LightGreen, GUILayout.Height(30))) { var newIndex = 0; var strNewIndex = ""; for (var i = 0; i < _selectedProperties.Length; i++) { if (_selectedProperties[i].LastName.Contains("NewProperty")) { newIndex++; } } if (newIndex > 0) { strNewIndex = newIndex.ToString(); } var newProperty = new CustomPropertyInfo("", typeof(string)) { LastName = "NewProperty" + strNewIndex }; ArrayUtility.Add(ref _selectedProperties, newProperty); CachePropertiesDrawer(); } //Save all change var changeList = new CustomPropertyInfo[0]; var selectedList = new CustomPropertyInfo[0]; for (var i = 0; i < _selectedProperties.Length; i++) { if (_selectedProperties[i].HasChange) { ArrayUtility.Add(ref changeList, _selectedProperties[i]); } if (_selectedProperties[i].IsSelected) { ArrayUtility.Add(ref selectedList, _selectedProperties[i]); } } GUILayout.Space(10); LineHelper.Draw(Color.gray); GUILayout.Space(5); if (changeList.Length > 0 || !string.Equals(_selectedType.Namespace, this.namespaceField.Text) || _selectedType.IsSealed != _selectedTypeIsSealed) { if (ColorButton.Draw("Save All Changes", CommonColor.LightGreen, GUILayout.Height(30))) { for (var i = 0; i < changeList.Length; i++) { changeList[i].CommitChange(); } SaveCurrentType(true, this.baseTypePopup.SelectedItem); } } if (selectedList.Length > 0) { if (ColorButton.Draw("Delete Selected Properties", CommonColor.LightRed, GUILayout.Height(30))) { for (var i = 0; i < selectedList.Length; i++) { ArrayUtility.Remove(ref _selectedProperties, selectedList[i]); } SaveCurrentType(true, this.baseTypePopup.SelectedItem); CachePropertiesDrawer(true); } } if (_selectedProperties.Length > 0) { if (ColorButton.Draw("Delete All Properties", CommonColor.LightRed, GUILayout.Height(30))) { while (_selectedProperties.Length > 0) { ArrayUtility.Clear(ref _selectedProperties); SaveCurrentType(); CachePropertiesDrawer(true); } } } }
void PropertiesWindow(int id = 2) { GUILayout.BeginVertical(); if (listTypes != null && !string.IsNullOrEmpty(listTypes.SelectedItem)) { if (selectedType != null) { // Title GUILayout.Space(2); LabelHelper.TitleLabel(selectedType.Name); LineHelper.Draw(Color.gray); // Common GUILayout.Space(2); if (selectedType.BaseType != typeof(ObservableModel)) { GUILayout.BeginHorizontal(); if (ColorButton.Draw("Edit View Logic (Handler)", CommonColor.LightBlue, GUILayout.Height(30))) { string handler = CodeGenerationHelper.GetScriptPathByType(selectedType); handler = handler.Replace(".cs", ".Handler.cs"); UnityEditorInternal.InternalEditorUtility.OpenFileAtLineExternal(handler, 1); } if (ColorButton.Draw("Edit View (UI)", CommonColor.LightBlue, GUILayout.Height(30))) { GameObject prefabInstance; UnityEngine.Object obj = FindObjectOfType(selectedType); if (obj != null) { prefabInstance = ((MonoBehaviour)obj).gameObject; } else { bool isDialog = selectedType.BaseType == typeof(UIManDialog); string prefabFolder = GetUIPrefabPath(selectedType, isDialog); string prefabFile = selectedType.Name + PREFAB_EXT; string prefabPath = Path.Combine(prefabFolder, prefabFile); GameObject prefab = AssetDatabase.LoadAssetAtPath <GameObject> (prefabPath); if (prefab == null) { prefab = FindAssetObject <GameObject> (selectedType.Name, PREFAB_EXT); } prefabInstance = PrefabUtility.InstantiatePrefab(prefab) as GameObject; if (isDialog) { prefabInstance.transform.SetParent(UIMan.Instance.dialogRoot, false); } else { prefabInstance.transform.SetParent(UIMan.Instance.screenRoot, false); } } Selection.activeGameObject = prefabInstance; } if (ColorButton.Draw("Delete", CommonColor.LightRed, GUILayout.Height(30))) { string cs = CodeGenerationHelper.GetScriptPathByType(selectedType); string handler = cs.Replace(".cs", ".Handler.cs"); AssetDatabase.DeleteAsset(cs); AssetDatabase.DeleteAsset(handler); bool isDialog = selectedType.BaseType == typeof(UIManDialog); string prefabFolder = GetUIPrefabPath(selectedType, isDialog); string prefabFile = selectedType.Name + PREFAB_EXT; string prefabPath = UIManDefine.ASSETS_FOLDER + prefabFolder + prefabFile; AssetDatabase.DeleteAsset(prefabPath); AssetDatabase.Refresh(); } GUILayout.EndHorizontal(); LineHelper.Draw(Color.gray); } // Base type GUILayout.Space(10); LabelHelper.HeaderLabel("Type"); LineHelper.Draw(Color.gray); baseTypePopup.Draw(); if (baseTypePopup.SelectedItem != "ObservableModel") { if (!System.IO.File.Exists(handlerScriptPath)) { if (GUILayout.Button("Generate Handler")) { string backupCode = CodeGenerationHelper.DeleteScript(handlerScriptPath); GenerateViewModelHandler(backupCode, selectedType.BaseType.Name); } } } // Properties GUILayout.Space(10); LabelHelper.HeaderLabel("Properties"); LineHelper.Draw(Color.gray); propertiesScrollPos = EditorGUILayout.BeginScrollView(propertiesScrollPos, GUILayout.ExpandWidth(true), GUILayout.ExpandHeight(true)); if (propertiesDrawerCache.ContainsKey(selectedType)) { EditablePropertyDrawer[] props = propertiesDrawerCache [selectedType]; for (int i = 0; i < props.Length; i++) { props [i].Draw(propertiesAreaWidth); } } EditorGUILayout.EndScrollView(); } GUILayout.Space(10); // Add property if (ColorButton.Draw("Add New Property", CommonColor.LightGreen, GUILayout.Height(30))) { int newIndex = 0; string strNewIndex = ""; for (int i = 0; i < selectedProperties.Length; i++) { if (selectedProperties [i].LastName.Contains("NewProperty")) { newIndex++; } } if (newIndex > 0) { strNewIndex = newIndex.ToString(); } CustomPropertyInfo newProperty = new CustomPropertyInfo("", typeof(string)); newProperty.LastName = "NewProperty" + strNewIndex; ArrayUtility.Add <CustomPropertyInfo> (ref selectedProperties, newProperty); CachePropertiesDrawer(); } //Save all change CustomPropertyInfo[] changeList = new CustomPropertyInfo[0]; CustomPropertyInfo[] selectedList = new CustomPropertyInfo[0]; for (int i = 0; i < selectedProperties.Length; i++) { if (selectedProperties [i].HasChange) { ArrayUtility.Add(ref changeList, selectedProperties [i]); } if (selectedProperties [i].IsSelected) { ArrayUtility.Add(ref selectedList, selectedProperties [i]); } } GUILayout.Space(10); LineHelper.Draw(Color.gray); GUILayout.Space(5); if (changeList.Length > 0) { if (ColorButton.Draw("Save All Changes", CommonColor.LightGreen, GUILayout.Height(30))) { for (int i = 0; i < changeList.Length; i++) { changeList [i].CommitChange(); } SaveCurrentType(true, baseTypePopup.SelectedItem); } } if (selectedList.Length > 0) { if (ColorButton.Draw("Delete Selected Properties", CommonColor.LightRed, GUILayout.Height(30))) { for (int i = 0; i < selectedList.Length; i++) { ArrayUtility.Remove(ref selectedProperties, selectedList [i]); } SaveCurrentType(true, baseTypePopup.SelectedItem); CachePropertiesDrawer(true); } } if (selectedProperties.Length > 0) { if (ColorButton.Draw("Delete All Properties", CommonColor.LightRed, GUILayout.Height(30))) { while (selectedProperties.Length > 0) { ArrayUtility.Clear(ref selectedProperties); SaveCurrentType(); CachePropertiesDrawer(true); } } } } else { GUILayout.Label("NO DATA FOR PREVIEW!"); } GUILayout.EndVertical(); }
private void UpdateLevelData() { ArrayUtility.Clear(ref levelData.RmbSubRecord.Exterior.Block3dObjectRecords); ArrayUtility.Clear(ref levelData.RmbSubRecord.Interior.Block3dObjectRecords); ArrayUtility.Clear(ref levelData.RmbSubRecord.Exterior.BlockFlatObjectRecords); ArrayUtility.Clear(ref levelData.RmbSubRecord.Interior.BlockFlatObjectRecords); ArrayUtility.Clear(ref levelData.RmbSubRecord.Exterior.BlockPeopleRecords); ArrayUtility.Clear(ref levelData.RmbSubRecord.Interior.BlockPeopleRecords); ArrayUtility.Clear(ref levelData.RmbSubRecord.Exterior.BlockDoorRecords); ArrayUtility.Clear(ref levelData.RmbSubRecord.Interior.BlockDoorRecords); Vector3 modelPosition; LocationEditorObject data; foreach (Transform child in parent.GetComponentInChildren <Transform>()) { if (child.GetComponent <LocationEditorObject>() == null) { return; } data = child.GetComponent <LocationEditorObject>(); //3D models if (data.type == (int)LocationEditorHelper.DataType.Object3D) { DaggerfallConnect.DFBlock.RmbBlock3dObjectRecord record = new DaggerfallConnect.DFBlock.RmbBlock3dObjectRecord(); record.ModelId = data.id; record.ModelIdNum = uint.Parse(data.id); record.ObjectType = data.objectType; if (data.objectType == 3) { Vector3[] vertices = child.GetComponent <MeshFilter>().sharedMesh.vertices; // Props axis needs to be transformed to lowest Y point Vector3 bottom = vertices[0]; for (int j = 0; j < vertices.Length; j++) { if (vertices[j].y < bottom.y) { bottom = vertices[j]; } } modelPosition = new Vector3(child.localPosition.x, (child.localPosition.y + (bottom.y)), child.localPosition.z) / MeshReader.GlobalScale; } else { modelPosition = new Vector3(child.localPosition.x, -child.localPosition.y, child.localPosition.z) / MeshReader.GlobalScale; } record.XPos = Mathf.RoundToInt(modelPosition.x); record.YPos = Mathf.RoundToInt(modelPosition.y); record.ZPos = Mathf.RoundToInt(modelPosition.z); record.XRotation = (short)(-child.eulerAngles.x * DaggerfallConnect.Arena2.BlocksFile.RotationDivisor); record.YRotation = (short)(-child.eulerAngles.y * DaggerfallConnect.Arena2.BlocksFile.RotationDivisor); record.ZRotation = (short)(-child.eulerAngles.z * DaggerfallConnect.Arena2.BlocksFile.RotationDivisor); record.XScale = child.localScale.x; record.YScale = child.localScale.y; record.ZScale = child.localScale.z; if (data.isExterior) { ArrayUtility.Add(ref levelData.RmbSubRecord.Exterior.Block3dObjectRecords, record); } else { ArrayUtility.Add(ref levelData.RmbSubRecord.Interior.Block3dObjectRecords, record); } } else if (data.type == (int)LocationEditorHelper.DataType.Flat) { DaggerfallConnect.DFBlock.RmbBlockFlatObjectRecord record = new DaggerfallConnect.DFBlock.RmbBlockFlatObjectRecord(); record.TextureArchive = int.Parse(data.id.Split('.')[0]); record.TextureRecord = int.Parse(data.id.Split('.')[1]); record.FactionID = data.factionID; record.Flags = data.flags; modelPosition = child.transform.localPosition / MeshReader.GlobalScale; record.XPos = Mathf.RoundToInt(modelPosition.x); record.YPos = Mathf.RoundToInt(-((child.localPosition.y - (child.GetComponent <DaggerfallBillboard>().Summary.Size.y / 2)) / MeshReader.GlobalScale)); record.ZPos = Mathf.RoundToInt(modelPosition.z); if (data.isExterior) { ArrayUtility.Add(ref levelData.RmbSubRecord.Exterior.BlockFlatObjectRecords, record); } else { ArrayUtility.Add(ref levelData.RmbSubRecord.Interior.BlockFlatObjectRecords, record); } } else if (data.type == (int)LocationEditorHelper.DataType.Person) { DaggerfallConnect.DFBlock.RmbBlockPeopleRecord record = new DaggerfallConnect.DFBlock.RmbBlockPeopleRecord(); record.TextureArchive = int.Parse(data.id.Split('.')[0]); record.TextureRecord = int.Parse(data.id.Split('.')[1]); record.FactionID = data.factionID; record.Flags = data.flags; modelPosition = child.transform.localPosition / MeshReader.GlobalScale; record.XPos = Mathf.RoundToInt(modelPosition.x); record.YPos = Mathf.RoundToInt(-((child.localPosition.y - (child.GetComponent <DaggerfallBillboard>().Summary.Size.y / 2)) / MeshReader.GlobalScale)); record.ZPos = Mathf.RoundToInt(modelPosition.z); if (data.isExterior) { ArrayUtility.Add(ref levelData.RmbSubRecord.Exterior.BlockPeopleRecords, record); } else { ArrayUtility.Add(ref levelData.RmbSubRecord.Interior.BlockPeopleRecords, record); } } else if (data.type == (int)LocationEditorHelper.DataType.Door) { DaggerfallConnect.DFBlock.RmbBlockDoorRecord record = new DaggerfallConnect.DFBlock.RmbBlockDoorRecord(); record.OpenRotation = data.openRotation; modelPosition = child.transform.localPosition / MeshReader.GlobalScale; record.XPos = Mathf.RoundToInt(modelPosition.x); record.YPos = -Mathf.RoundToInt(modelPosition.y); record.ZPos = Mathf.RoundToInt(modelPosition.z); record.YRotation = (short)(-child.eulerAngles.y * DaggerfallConnect.Arena2.BlocksFile.RotationDivisor); if (data.isExterior) { ArrayUtility.Add(ref levelData.RmbSubRecord.Exterior.BlockDoorRecords, record); } else { ArrayUtility.Add(ref levelData.RmbSubRecord.Interior.BlockDoorRecords, record); } } } }