/// <summary> /// Export an AnimationCurve. /// NOTE: This is not used for rotations, because we need to convert from /// quaternion to euler and various other stuff. /// </summary> protected void ExportAnimCurve(UnityEngine.Object unityObj, AnimationCurve unityAnimCurve, string unityPropertyName, FbxScene fbxScene, FbxAnimLayer fbxAnimLayer) { FbxPropertyChannelPair fbxPropertyChannelPair; if (!FbxPropertyChannelPair.TryGetValue(unityPropertyName, out fbxPropertyChannelPair)) { Debug.LogWarning(string.Format("no mapping from Unity '{0}' to fbx property", unityPropertyName)); return; } GameObject unityGo = GetGameObject(unityObj); if (unityGo == null) { Debug.LogError(string.Format("cannot find gameobject for {0}", unityObj.ToString())); return; } FbxNode fbxNode; if (!MapUnityObjectToFbxNode.TryGetValue(unityGo, out fbxNode)) { Debug.LogError(string.Format("no fbx node for {0}", unityGo.ToString())); return; } // map unity property name to fbx property var fbxProperty = fbxNode.FindProperty(fbxPropertyChannelPair.Property, false); if (!fbxProperty.IsValid()) { Debug.LogError(string.Format("no fbx property {0} found on {1} ", fbxPropertyChannelPair.Property, fbxNode.GetName())); return; } if (Verbose) { Debug.Log("Exporting animation for " + unityObj.ToString() + " (" + unityPropertyName + ")"); } // Create the AnimCurve on the channel FbxAnimCurve fbxAnimCurve = fbxProperty.GetCurve(fbxAnimLayer, fbxPropertyChannelPair.Channel, true); // copy Unity AnimCurve to FBX AnimCurve. fbxAnimCurve.KeyModifyBegin(); for (int keyIndex = 0, n = unityAnimCurve.length; keyIndex < n; ++keyIndex) { var key = unityAnimCurve [keyIndex]; var fbxTime = FbxTime.FromSecondDouble(key.time); fbxAnimCurve.KeyAdd(fbxTime); fbxAnimCurve.KeySet(keyIndex, fbxTime, key.value); } fbxAnimCurve.KeyModifyEnd(); }
public static GameObject SingleInstanceObjectWithTag(UnityEngine.Object caller, string tag, string errorOnNotFound, string multiplesInstance) { GameObject[] gameObjects = GameObject.FindGameObjectsWithTag(tag); if (gameObjects.Length == 0) { throw new UnityException(errorOnNotFound + CombineCharacters.SpaceColonSpace + ErrorsAuxs.Caller + caller.ToString() + CombineCharacters.CommaSpace + ErrorsAuxs.Tag + tag); } else if (gameObjects.Length > 1) { throw new UnityException(multiplesInstance + CombineCharacters.SpaceColonSpace + ErrorsAuxs.Caller + caller.ToString() + CombineCharacters.CommaSpace + ErrorsAuxs.Tag + tag); } else { return(gameObjects[0]); } }
private void ShowLightSelfInList() { Object firstObject = null; if (objectsToLight.arraySize > 0) { firstObject = objectsToLight.GetArrayElementAtIndex(0).objectReferenceValue; } if (lightSelf.boolValue) { if (firstObject == null || firstObject.ToString() != lightBehaviour.gameObject.ToString()) { objectsToLight.arraySize++; objectsToLight.GetArrayElementAtIndex(0).objectReferenceValue = lightBehaviour.gameObject; } } else if (firstObject != null && firstObject.ToString() == lightBehaviour.gameObject.ToString()) { objectsToLight.DeleteArrayElementAtIndex(0); objectsToLight.arraySize--; } serializedObject.ApplyModifiedProperties(); }
public static string GetNativeObjectType(Object unityObject) { string result; try { var fullName = unityObject.ToString(); var openingIndex = fullName.IndexOf('(') + 1; if (openingIndex != 0) { var closingIndex = fullName.LastIndexOf(')'); result = fullName.Substring(openingIndex, closingIndex - openingIndex); } else { result = null; } } catch { result = null; } return(result); }
//--- Unity Ads Setup and Initialization void Start() { UnityEngine.Object obj = Resources.Load("UAD/UADDATA"); if (obj) { string dataAsYaml = obj.ToString(); Deserializer deserializer = new Deserializer(); Dictionary <string, string> dic = deserializer.Deserialize <Dictionary <string, string> >(new StringReader(dataAsYaml)); string key = ""; #if UNITY_IOS key = "ios"; #elif UNITY_ANDROID key = "android"; #endif if (dic != null && dic.ContainsKey(key)) { string gameId = dic[key]; Advertisement.Initialize(gameId); Debug.LogWarning("QIPAWORLD:广告ID" + gameId); } else { Debug.LogWarning("QIPAWORLD:没有广告ID 配置文件位置Resources/UAD/UADDATA"); UIController.Instance.PushHint("没有广告ID", "没有广告ID 配置文件位置Resources/UAD/UADDATA", null, true); } } else { Debug.LogError("QIPAWORLD:没有广告配置文件 Resources/UAD/UADDATA"); UIController.Instance.PushHint("没有广告ID", "没有广告配置文件 Resources/UAD/UADDATA", null, true); } }
/// <summary> /// 重新加载配置表 /// </summary> /// <typeparam name="T"></typeparam> /// <param name="source"></param> /// <returns></returns> public static async Task ReloadConfig <T>(Dictionary <object, T> source) where T : BaseConfig { string fileName = typeof(T).Name; source.Clear(); UnityEngine.Object configObj = await GameFrameEntry.GetModule <AssetbundleModule>().LoadAsset <UnityEngine.Object>(configAssetbundle, fileName); if (configObj != null) { string strconfig = configObj.ToString(); List <T> list = JsonMapper.ToObject <List <T> >(strconfig); for (int i = 0; i < list.Count; i++) { if (source.ContainsKey(list[i].UniqueID)) { CLog.Error($"表[{fileName}]中有相同键({list[i].UniqueID})"); } else { source.Add(list[i].UniqueID, list[i]); } } } else { CLog.Error($"配置文件不存在{fileName}"); } }
public static void Destroy(GameObject obj, UnityEngine.Object baseObjectHint) { foreach (string alert in debugAlerts) { if (obj.name.Contains(alert)) { Debug.Log("Destroy (with hint): " + obj.name); break; } } //Debug.Log("ObjectPool.Destroy(obj)"); if (baseObjectHint == null) { Debug.Log("Pool.Destroy called with null baseObject key"); return; } if (!pools.ContainsKey(baseObjectHint)) { Debug.Log("Pool.Destroy called with unknown baseObject key " + baseObjectHint.ToString()); return; } pools [baseObjectHint].Destroy(obj); }
//RectTransform topR; void Start() { layout = target.GetComponent <VerticalLayoutGroup>(); GameObject tatle = GameObjManager.Instance.GetGameObj("UIPrefabs/AcknowledgementLayerCellText", target); tatle.GetComponent <LocalizedText>().UpdateText("鸣谢"); updatePosition(tatle); //tatle.transform.position = new Vector3(tatle.transform.position.x, -30, tatle.transform.position.z); UnityEngine.Object obj = Resources.Load("Acknowledgement/AcknowledgementDATA"); if (obj) { string dataAsYaml = obj.ToString(); Deserializer deserializer = new Deserializer(); Dictionary <string, List <string> > dic = deserializer.Deserialize <Dictionary <string, List <string> > >(new StringReader(dataAsYaml)); //topR = tatle.GetComponent<RectTransform>(); foreach (var kv in dic) { GameObject tempTatle = GameObjManager.Instance.GetGameObj("UIPrefabs/AcknowledgementLayerCellText", target); tempTatle.GetComponent <LocalizedText>().UpdateText(kv.Key); updatePosition(tempTatle); foreach (string s in kv.Value) { string[] dataStr = s.Split(','); GameObject cell = GameObjManager.Instance.GetGameObj("UIPrefabs/AcknowledgementLayerCell", target); cell.GetComponent <AcknowledgementLayerCell>().Init(dataStr[0], dataStr[1]); updatePosition(cell); } } } }
static int Lua_ToString(IntPtr l) { Object obj = (Object)luaMgr.GetNetObject(1); luaMgr.PushResult(obj.ToString()); return(1); }
private bool readFile(string[] name, int[] value) { UnityEngine.Object configFile = Resources.Load("Setting Files/keyboard config"); if (configFile == null) { return(false); } string[] lines = configFile.ToString().Split('\n'); if (lines.Length != 4) { return(false); } int index = 0; foreach (string line in lines) { string[] temp = line.Split(' '); if (temp.Length != 2) { return(false); } name[index] = temp[0]; value[index] = int.Parse(temp[1]); index++; } return(true); }
protected override void replace(SearchJob job, SerializedProperty prop, SearchResult result) { #if PSR_FULL if(prop.name == "m_Script") { if(replaceValue.obj == null) { //don't do it. result.actionTaken = SearchAction.Error; result.replaceStrRep = "(null)"; result.error = "Cannot set a MonoBehaviour's Script to null."; return; } } if(typeof(Component).IsAssignableFrom(type)) { GameObject go = ObjectUtil.GetGameObject(prop.serializedObject.targetObject); UnityEngine.Object replaceVal = go.GetComponent(type); prop.objectReferenceValue = replaceVal; // prop.objectReferenceValue = replaceValue.obj; string objName = replaceVal == null ? "(null)" : replaceVal.ToString(); result.replaceStrRep = objName; } #endif }
/****************************************************************************************************/ void Start() { if (ConnectOnPlay) { charSetupLoaded = LoadCharSetupFile(ExpressionSetFile.ToString()); if (charSetupLoaded) { List <string> missingCtrlList = LiveUnityInterface.ValidateControls(data.GetControlList()); if (missingCtrlList.Count > 0) { string msg = "These controls are not in your scene:\n"; foreach (string ctrl in missingCtrlList) { msg += ctrl; msg += "\n"; } PrintError(msg); } controlOffsets = data.GetNeutralControlValues(); } network.Connect(Server, Port); ConnectOnPlay = false; PrintMessage("LiveClient started."); PrintMessage(charSetupLoaded ? "Loaded Character Setup file." : "No Character Setup file loaded."); //PrintMessage( connected ? "Connected to Live Server." : "Could not connect to Live Server. Check your hostname/port and make sure that Live Server is streaming data." ); } }
static int Lua_ToString(IntPtr L) { Object obj = (Object)LuaScriptMgr.GetNetObject(L, 1); LuaScriptMgr.PushResult(L, obj.ToString()); return(1); }
public StaticAnalysisEntry( Object asset, string assetAlias, string assetCategory, ShaderProgramFilter filter, string filterName, string filterCategory, string testName, BuildTarget buildTarget, float timeout ) { errorString = null; this.asset = asset; this.filter = filter; this.buildTarget = buildTarget; this.timeout = timeout; this.testName = new TestName( string.IsNullOrEmpty(assetAlias) ? asset.ToString() : assetAlias, assetCategory, filterName, filterCategory, testName ); }
static int Lua_ToString(IntPtr L) { Object obj = LuaScriptMgr.GetNetObject <Object>(L, 1); LuaScriptMgr.Push(L, obj.ToString()); return(1); }
public void Load() { GameDatas = new List <GameData>(); UnityEngine.Object obj = Resources.Load(LoadName); string str = obj == null ? "" : obj.ToString(); if (!string.IsNullOrEmpty(str)) { GameData data; List <GameData> SourceGameDatas = JsonConvert.DeserializeObject <List <GameData> >(str); foreach (var item in SourceGameDatas) { if (TypeFilter != null) { if (!TypeFilter.Contains(item.DataType)) { continue; } } data = CreateGameData(item, false); GameDatas.Add(data); } } }
private string GetLabelText(GUIContent label) { if (label != null) { return(label.text); } object val = Property.ValueEntry.WeakSmartValue; if (val == null) { return("Null"); } Object unityObject = val as Object; if (unityObject) { if (string.IsNullOrEmpty(unityObject.name)) { return(unityObject.ToString()); } return(unityObject.name); } return(val.ToString()); }
public override string ToString() { if (!(value == null)) { return(value.ToString()); } return("None"); }
public static UnityEngine.Object SceneField(string label, UnityEngine.Object obj) { if ((obj != null) && !obj.ToString().EndsWith(".SceneAsset")) { obj = null; } return(EditorGUILayout.ObjectField(label, obj, typeof(UnityEngine.Object), false, new GUILayoutOption[0])); }
public XmlDocument ReadFile(string fileName) { UnityEngine.Object dragonBasic = Resources.Load("AI/Behaviours/" + fileName); XmlDocument xml = new XmlDocument(); xml.LoadXml(dragonBasic.ToString()); return(xml); }
public static UnityEngine.Object SceneField(Rect rect, string label, UnityEngine.Object obj) { if ((obj != null) && !obj.ToString().EndsWith(".SceneAsset")) { obj = null; } return(EditorGUI.ObjectField(rect, label, obj, typeof(UnityEngine.Object), false)); }
public static Component ComponentInChild(UnityEngine.Object caller, GameObject gameObject, Type type, int position) { Component component = null; Component[] components = gameObject.GetComponentsInChildren(type); if (components.Length == 0) { throw new UnityException(Errors.DefaultErrorComponentInChildNotFound + CombineCharacters.SpaceColonSpace + ErrorsAuxs.Caller + caller.ToString() + CombineCharacters.CommaSpace + ErrorsAuxs.GameObject + gameObject.ToString() + CombineCharacters.CommaSpace + ErrorsAuxs.Type + type.ToString() + CombineCharacters.CommaSpace + ErrorsAuxs.Position + position); } try { component = components[position]; } catch (Exception) { throw new UnityException(Errors.DefaultErrorComponentInChildNotFoundInPosition + CombineCharacters.SpaceColonSpace + ErrorsAuxs.Caller + caller.ToString() + CombineCharacters.CommaSpace + ErrorsAuxs.GameObject + gameObject.ToString() + CombineCharacters.CommaSpace + ErrorsAuxs.Type + type.ToString() + CombineCharacters.CommaSpace + ErrorsAuxs.Position + position); } return(component); }
public void Read_From_Resource(string _fileName) { UnityEngine.Object @object = Resources.Load <UnityEngine.Object>(_fileName); if (this.debug) { Debug.Log("IniFile Read File from Resource:\n" + @object); } this.Read_From_String(@object.ToString()); }
static string fullPath(Object o) { var go = o as GameObject; return (go && go.transform.parent != null ? $"[{fullPath(go.transform.parent.gameObject)}]/{go}" : o.ToString()); }
/// <summary>Appends a description of this call.</summary> public void ToString(StringBuilder text) { text.Append("PersistentCall: MethodName="); text.Append(_MethodName); text.Append(", Target="); text.Append(_Target != null ? _Target.ToString() : "null"); text.Append(", PersistentArguments="); UltEventUtils.AppendDeepToString(text, _PersistentArguments.GetEnumerator(), "\n "); }
static int ToString(IntPtr l) { luaMgr.CheckArgsCount(1); Object obj = (Object)luaMgr.GetNetObject(1); string o = obj.ToString(); luaMgr.PushResult(o); return(1); }
static int ToString(IntPtr L) { LuaScriptMgr.CheckArgsCount(L, 1); Object obj = (Object)LuaScriptMgr.GetUnityObjectSelf(L, 1, "Object"); string o = obj.ToString(); LuaScriptMgr.Push(L, o); return(1); }
public static void Log(object message, UnityEngine.Object context, DebugGroup group = DebugGroup.All) { #if DEBUG if ((logMask & (int)group) > 0) { Debug.LogFormat(context.ToString(), MESSAGE_FORMAT, message, group); } #endif }
private static int ToString(IntPtr L) { LuaScriptMgr.CheckArgsCount(L, 1); UnityEngine.Object @object = (UnityEngine.Object)LuaScriptMgr.GetUnityObjectSelf(L, 1, "Object"); string str = @object.ToString(); LuaScriptMgr.Push(L, str); return(1); }
static int ToString(IntPtr L) { LuaScriptMgr.CheckArgsCount(L, 1); Object obj = (Object)LuaScriptMgr.GetNetObject(L, 1); string o = obj.ToString(); LuaScriptMgr.PushResult(L, o); return(1); }
private Object ValidateLevelScene(Object levelScene) { if (levelScene != null) { string name = levelScene.ToString (); if (name.Contains (" (UnityEngine.SceneAsset)") && name.Contains (LevelsPackage.Suffix)) { return levelScene; } } return null; }
private void OpenMonoScript() { string path = EditorUtility.OpenFilePanel( "Open A Template", XEditorSetting.ProjectPath, "" ); if( path == "" ) return; path = FileUtil.GetProjectRelativePath( path ); ScriptFile = AssetDatabase.LoadAssetAtPath<MonoScript>( path ); XLogger.Log( "script is : " + ScriptFile.ToString() ); }
private static ObjectType GetObjectType(Object activeObject) { if (activeObject == null) return ObjectType.None; if (activeObject is GameObject) { if (Instance._breadcrumbs != null) if (activeObject == Instance._breadcrumbs.gameObject) return ObjectType.InspectorBreadcrumbs; PrefabType pt = PrefabUtility.GetPrefabType((GameObject)activeObject); if (pt == PrefabType.None || pt == PrefabType.DisconnectedModelPrefabInstance || pt == PrefabType.DisconnectedPrefabInstance || pt == PrefabType.MissingPrefabInstance || pt == PrefabType.ModelPrefabInstance || pt == PrefabType.PrefabInstance) return ObjectType.Instance; } if (activeObject as UnityEngine.TextAsset != null) return ObjectType.TextAssets; if (activeObject.ToString().Contains("UnityEngine.SceneAsset")) return ObjectType.Scene; var asset_path = AssetDatabase.GetAssetPath(activeObject); if (string.IsNullOrEmpty(asset_path)) { if (activeObject.GetType().ToString().Contains("AssetStoreAssetInspector")) return ObjectType.AssetStoreAssetInspector; else return ObjectType.Asset; } if (asset_path.StartsWith("ProjectSettings/")) return ObjectType.ProjectSettings; try { System.IO.FileAttributes file_attr = System.IO.File.GetAttributes(Application.dataPath + "/" + asset_path.Replace("Assets/", "")); if ((file_attr & System.IO.FileAttributes.Directory) == System.IO.FileAttributes.Directory) return ObjectType.Folder; } catch { } return ObjectType.Asset; }
void OnGUI() { if (!init) Init(); bool hoverSelected = false; Event e = Event.current; EditorPlusHistoryInternal.CheckConsistency(); widgetHostFavs.Area = position; widgetHostFavs.WidgetsCount = EditorPlusHistoryInternal.favorites.Count + 1; widgetHostFavs.Update(); favsView = new Rect(0, 0, position.width, widgetHostFavs.GetYMax()); historyView = new Rect(0, widgetHostFavs.GetYMax(), position.width, position.height - favsView.height); widgetHostHistory.Area = position; widgetHostHistory.WidgetsCount = EditorPlusHistoryInternal.history.Count; widgetHostHistory.Update(); //drag and drop sorting if (favsView.Contains(e.mousePosition) && DragAndDrop.objectReferences.Length > 0 && DragAndDrop.objectReferences[0] == selectedObj && (EditorPlusHistoryInternal.favorites.Contains(selectedObj) || EditorPlusHistoryInternal.history.Contains(selectedObj))) { DragAndDrop.visualMode = DragAndDropVisualMode.Link; if (e.rawType == EventType.DragPerform) { int index = widgetHostFavs.FindClosestWidget(e.mousePosition); bool abort = false; if (index - 1 == EditorPlusHistoryInternal.favorites.IndexOf(selectedObj)) { DragAndDrop.PrepareStartDrag(); abort = true; } else if(index - 1 <= 0) { if (!EditorPlusHistoryInternal.favorites.Contains(selectedObj)) { EditorPlusHistoryInternal.AddToFavorites(selectedObj); widgetHostFavs.WidgetsCount = EditorPlusHistoryInternal.favorites.Count + 1; widgetHostFavs.Update(); } EditorPlusHistoryInternal.SetFavoritePosition(0, selectedObj); abort = true; } //check if widget + margin.x contains mouse position and insert there if (!abort && e.mousePosition.x > widgetHostFavs.Widgets[index].x && e.mousePosition.x < widgetHostFavs.Widgets[index].x + widgetHostFavs.Widgets[index].width + widgetHostFavs.WidgetMargin.x && e.mousePosition.y > widgetHostFavs.Widgets[index].y && e.mousePosition.y < widgetHostFavs.Widgets[index].y + widgetHostFavs.Widgets[index].height) { //left or right if (e.mousePosition.x < widgetHostFavs.Widgets[index].x + widgetHostFavs.Widgets[index].width / 2) { if (!EditorPlusHistoryInternal.favorites.Contains(selectedObj)) { EditorPlusHistoryInternal.AddToFavorites(selectedObj); widgetHostFavs.WidgetsCount = EditorPlusHistoryInternal.favorites.Count + 1; widgetHostFavs.Update(); } EditorPlusHistoryInternal.SetFavoritePosition(index - 1, selectedObj); } else { if (!EditorPlusHistoryInternal.favorites.Contains(selectedObj)) { EditorPlusHistoryInternal.AddToFavorites(selectedObj); widgetHostFavs.WidgetsCount = EditorPlusHistoryInternal.favorites.Count + 1; widgetHostFavs.Update(); } EditorPlusHistoryInternal.SetFavoritePosition(index, selectedObj); } } else if (!abort) { if (!EditorPlusHistoryInternal.favorites.Contains(selectedObj)) { EditorPlusHistoryInternal.AddToFavorites(selectedObj); widgetHostFavs.WidgetsCount = EditorPlusHistoryInternal.favorites.Count + 1; widgetHostFavs.Update(); } EditorPlusHistoryInternal.SetFavoritePosition(EditorPlusHistoryInternal.favorites.Count, selectedObj); } } } float scrollViewFavsHeight = 0f; if (widgetHostFavs.Widgets.Count > 0) { scrollViewFavsHeight = widgetHostFavs.Widgets[widgetHostFavs.Widgets.Count - 1].yMax; } float scrollViewHistHeight = 0f; if (widgetHostHistory.Widgets.Count > 0) { scrollViewHistHeight = widgetHostHistory.Widgets[widgetHostHistory.Widgets.Count - 1].yMax; } if (position.height < scrollViewFavsHeight + scrollViewHistHeight) { widgetHostFavs.Area = new Rect(0, 0, favsView.width - GUI.skin.verticalScrollbar.normal.background.width, favsView.height); widgetHostFavs.Update(); widgetHostHistory.Area = new Rect(0, historyView.y, historyView.width - GUI.skin.verticalScrollbar.normal.background.width, historyView.height); widgetHostHistory.Update(); } GUISkin old = GUI.skin; GUI.skin = EditorPlus.ScrollviewSkin; historyViewPos = GUI.BeginScrollView(new Rect(0, 0, position.width, position.height), historyViewPos, new Rect(0, 0, position.width - 30, scrollViewFavsHeight + scrollViewHistHeight)); GUI.skin = old; if (GUI.skin != IconsSkinFav) GUI.skin = IconsSkinFav; //Navigation Arrows Rect r = widgetHostFavs.Widgets[0]; if (GUI.Button(new Rect(r.x, r.y, r.width / 2 - ButtonMargin.x - LockClosed.width, r.height), new GUIContent("Prev", Prev)) || (e.isMouse && e.button == 3)) { EditorPlusHistoryInternal.HistoryNavigationBack(); } if (GUI.Button(new Rect(r.x + r.width / 2, r.y, r.width / 2, r.height), new GUIContent("Next", Next))) { EditorPlusHistoryInternal.HistoryNavigationForward(); } //----------------------------------------------- //draw favorites for (int i = 0; i < EditorPlusHistoryInternal.favorites.Count; ++i) { if (GUI.skin != IconsSkinFav) GUI.skin = IconsSkinFav; r = widgetHostFavs.Widgets[i + 1]; if (e.rawType == EventType.MouseDown) { if (r.Contains(e.mousePosition)) { //Drag object if (e.button == 0) { highlightInFavs = true; if (e.clickCount != 2) { selectedObj = EditorPlusHistoryInternal.favorites[i]; DragAndDrop.PrepareStartDrag(); if (selectedObj.GetType() != typeof(UnityEngine.GameObject)) DragAndDrop.paths = new string[] { AssetDatabase.GetAssetPath(selectedObj) }; DragAndDrop.objectReferences = new Object[] { selectedObj }; DragAndDrop.StartDrag(selectedObj.ToString()); } else if (e.clickCount == 2) { Selection.activeObject = EditorPlusHistoryInternal.favorites[i]; if (Selection.activeObject.GetType() != typeof(UnityEngine.GameObject)) { if (Selection.activeObject.GetType() == EditorPlus.EPlusDefaultType) { string path = AssetDatabase.GetAssetPath(Selection.activeObject); if (Directory.Exists(path)) { string[] subFolders = Directory.GetDirectories(path); if (subFolders.Length != 0) { AssetDatabase.OpenAsset(AssetDatabase.LoadMainAssetAtPath(subFolders[0])); break; } string[] content = Directory.GetFiles(path); if (content.Length == 0) { EditorGUIUtility.PingObject(Selection.activeObject); } else { foreach (string file in content) { Object asset = AssetDatabase.LoadMainAssetAtPath(file); if (asset != null) { EditorGUIUtility.PingObject(asset); break; } } } } } else { EditorGUIUtility.PingObject(Selection.activeObject); } } } } hoverSelected = true; } } else if (e.rawType == EventType.MouseUp && r.Contains(e.mousePosition)) hoverSelected = true; GUIContent cnt = new GUIContent(EditorPlusHistoryInternal.favorites[i].name); if (cnt.text == "") { cnt.text = "Noname"; } if (showLabels) { Texture2D prev = AssetPreview.GetAssetPreview(EditorPlusHistoryInternal.favorites[i]); if (prev == null) { prev = (Texture2D)AssetDatabase.GetCachedIcon(AssetDatabase.GetAssetPath(EditorPlusHistoryInternal.favorites[i])); if (EditorPlusHistoryInternal.favorites[i].GetType() == typeof(UnityEngine.GameObject)) { prev = GameObjectLabel; } } GUI.Label(new Rect(r.x, r.y, 32 * widgetHostFavs.WidgetScale, r.height), prev, ((selectedObj == EditorPlusHistoryInternal.favorites[i] && highlightInFavs)) ? new GUIStyle(GUI.skin.box) : new GUIStyle(GUI.skin.button)); r.x += 20 * widgetHostFavs.WidgetScale; r.width -= 20 * widgetHostFavs.WidgetScale; } GUI.Label(r, cnt, ((selectedObj == EditorPlusHistoryInternal.favorites[i] && highlightInFavs)) ? new GUIStyle(GUI.skin.box) : new GUIStyle(GUI.skin.button)); Rect lockButton = new Rect(r.x + r.width, r.y + 5, LockClosed.width, LockClosed.height); if (GUI.skin != IconsSkinLock) GUI.skin = IconsSkinLock; if (GUI.Button(lockButton, LockClosed)) { EditorPlusHistoryInternal.RemoveFromFavorites(EditorPlusHistoryInternal.favorites[i]); --i; hoverSelected = true; repaintNextUpdate = true; continue; } } if (GUI.skin != IconsSkin) GUI.skin = IconsSkin; //historyViewPos = GUI.BeginScrollView(historyView, historyViewPos, new Rect(0, 0, position.width - 30, scrollViewHistHeight)); historyView.height = scrollViewHistHeight; GUI.BeginGroup(historyView); //----------------------------------------------- //draw history for (int i = 0; i < EditorPlusHistoryInternal.history.Count; ++i) { if (i == historySize) break; if (GUI.skin != IconsSkin) GUI.skin = IconsSkin; if (EditorPlusHistoryInternal.history[i] == null) { EditorPlusHistoryInternal.RemoveFromHistory(EditorPlusHistoryInternal.history[i], true); --i; continue; } r = widgetHostHistory.Widgets[i]; if (e.rawType == EventType.MouseDown) { if (r.Contains(e.mousePosition)) { //Drag object if (e.button == 0) { highlightInFavs = false; if (e.clickCount != 2) { selectedObj = EditorPlusHistoryInternal.history[i]; DragAndDrop.PrepareStartDrag(); string path = AssetDatabase.GetAssetPath(selectedObj); if (path != "") DragAndDrop.paths = new string[] { path }; if (selectedObj != null) DragAndDrop.objectReferences = new Object[] { selectedObj }; DragAndDrop.StartDrag(selectedObj.ToString()); } else if (e.clickCount == 2) { Selection.activeObject = EditorPlusHistoryInternal.history[i]; if (Selection.activeObject.GetType() != typeof(UnityEngine.GameObject)) { if (Selection.activeObject.GetType() == EditorPlus.EPlusDefaultType) { string path = AssetDatabase.GetAssetPath(Selection.activeObject); if (Directory.Exists(path)) { string[] subFolders = Directory.GetDirectories(path); if (subFolders.Length != 0) { AssetDatabase.OpenAsset(AssetDatabase.LoadMainAssetAtPath(subFolders[0])); break; } string[] content = Directory.GetFiles(path); if (content.Length == 0) { EditorGUIUtility.PingObject(Selection.activeObject); } else { foreach (string file in content) { Object asset = AssetDatabase.LoadMainAssetAtPath(file); if (asset != null) { EditorGUIUtility.PingObject(asset); break; } } } } } else { EditorGUIUtility.PingObject(Selection.activeObject); } } } } hoverSelected = true; } } else if(e.rawType == EventType.MouseUp && r.Contains(e.mousePosition)) hoverSelected = true; GUIContent cnt = new GUIContent(EditorPlusHistoryInternal.history[i].name); if(cnt.text == "") { cnt.text = "Noname"; } //Debug.Log(GUI.skin.box.CalcSize(new GUIContent(cnt.text)).x + " " + GUI.skin.box.padding.left + " " + GUI.skin.box.padding.right); if (showLabels) { Texture2D prev = AssetPreview.GetAssetPreview(EditorPlusHistoryInternal.history[i]); if (prev == null) { prev = (Texture2D)AssetDatabase.GetCachedIcon(AssetDatabase.GetAssetPath(EditorPlusHistoryInternal.history[i])); if (EditorPlusHistoryInternal.history[i].GetType() == typeof(UnityEngine.GameObject)) { prev = GameObjectLabel; } } GUI.Label(new Rect(r.x, r.y, 32 * widgetHostHistory.WidgetScale, r.height), prev, ((selectedObj == EditorPlusHistoryInternal.history[i] && !highlightInFavs)) ? new GUIStyle(GUI.skin.box) : new GUIStyle(GUI.skin.button)); r.x += 20 * widgetHostHistory.WidgetScale; r.width -= 20 * widgetHostHistory.WidgetScale; } GUI.Label(r, cnt, ((selectedObj == EditorPlusHistoryInternal.history[i] && !highlightInFavs)) ? new GUIStyle(GUI.skin.box) : new GUIStyle(GUI.skin.button)); Rect lockButton = new Rect(r.x + r.width, r.y + 5, LockOpen.width, LockOpen.height); if (GUI.skin != IconsSkinLock) GUI.skin = IconsSkinLock; if (!EditorPlusHistoryInternal.favorites.Contains(EditorPlusHistoryInternal.history[i]) && GUI.Button(lockButton, LockOpen)) { EditorPlusHistoryInternal.AddToFavorites(EditorPlusHistoryInternal.history[i]); --i; hoverSelected = true; repaintNextUpdate = true; continue; } } GUI.EndGroup(); GUI.EndScrollView(); //Reset Inspector if mouse up inside the window but not on button bool inside = false; if (e.mousePosition.x > 0f && e.mousePosition.x < window.position.width && e.mousePosition.y > 0f && e.mousePosition.y < window.position.height) { inside = true; } if (inside && !hoverSelected && e.rawType == EventType.MouseUp) { selectedObj = null; Selection.activeObject = null; } if ((e.rawType == EventType.MouseUp || e.rawType == EventType.dragPerform) && DragAndDrop.objectReferences != null) { DragAndDrop.PrepareStartDrag(); } }
void OnGUI() { GUILayout.BeginHorizontal(); bool retVal = GUILayout.Button("Add To", GUILayout.Width(76f)); GUI.color = Color.white; GUILayout.Label("Select the parent in the Hierarchy View", GUILayout.MinWidth(10000f)); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.Label("Select TexturePacker metafile"); m_TexturePackerMetafile = EditorGUILayout.ObjectField(m_TexturePackerMetafile, typeof(TextAsset), false); GUILayout.EndHorizontal(); if (retVal) { if(m_TexturePackerMetafile != null) { Dictionary<string, UITextureInfo> test = loadTexturesFromTexturePackerJSON(m_TexturePackerMetafile.ToString()); foreach(KeyValuePair<string, UITextureInfo> u in test) { Debug.Log(u.Key); Debug.Log(u.Value); } } Debug.Log("yay!"); //CreateMeshes(); } }
protected override void OnUpdateGUI() { value = GetValue<UnityEngine.Object>(); dropbox.text = (value == null ? "null" : value.ToString()); }
void OnGUI() { if (init == false) return; if (GUI.skin != skin) GUI.skin = skin; Event e = Event.current; bool insideWindow = false; if (e.mousePosition.x > 0f && e.mousePosition.x < position.width && e.mousePosition.y > 0f && e.mousePosition.y < position.height && (DragAndDrop.objectReferences.Length > 0 && AssetDatabase.GetAssetPath(DragAndDrop.objectReferences[0]) != "")) { insideWindow = true; DragAndDrop.visualMode = DragAndDropVisualMode.Link; if (e.rawType == EventType.DragPerform) { foreach (Object obj in DragAndDrop.objectReferences) { if (AssetDatabase.GetAssetPath(obj) != "") { //if list is empty, add and continue if(hotbarObjects.Count == 0) { hotbarObjects.Add(obj); continue; } int index = widgetHost.FindClosestWidget(e.mousePosition); if (index == hotbarObjects.IndexOf(obj)) { selectedObj = obj; Selection.activeObject = obj; break; } else if (hotbarObjects.Contains(obj)) { hotbarObjects.Remove(obj); hotbarPreviewCache.Remove(obj); } //check if widget + margin.x contains mouse position and insert there if (e.mousePosition.x > widgetHost.Widgets[index].x && e.mousePosition.x < widgetHost.Widgets[index].x + widgetHost.Widgets[index].width + widgetHost.WidgetMargin.x && e.mousePosition.y > widgetHost.Widgets[index].y && e.mousePosition.y < widgetHost.Widgets[index].y + widgetHost.Widgets[index].height) { //left or if(e.mousePosition.x < widgetHost.Widgets[index].x + widgetHost.Widgets[index].width / 2) { hotbarObjects.Insert(index, obj); } //right else { if (index < hotbarObjects.Count) hotbarObjects.Insert(index + 1, obj); else hotbarObjects.Add(obj); } } else { hotbarObjects.Add(obj); } } } if(useAutoSave) { SaveHotbar(); } } } if (e.isKey && e.keyCode == KeyCode.Delete && selectedObj != null) { hotbarObjects.Remove(selectedObj); hotbarPreviewCache.Remove(selectedObj); if (useAutoSave) { SaveHotbar(); } } //reset if (e.rawType == EventType.MouseDown) { selectedObj = null; } widgetHost.Area = position; widgetHost.WidgetsCount = hotbarObjects.Count; widgetHost.Update(); bool hoverSelected = false; float scrollviewHeight = position.height; if(widgetHost.Widgets.Count > 0) { if(widgetHost.Widgets[widgetHost.Widgets.Count - 1].yMax > scrollviewHeight) scrollviewHeight = widgetHost.Widgets[widgetHost.Widgets.Count - 1].yMax; } GUISkin old = GUI.skin; GUI.skin = EditorPlus.ScrollviewSkin; scrollviewPosition = GUI.BeginScrollView(new Rect(0, 0, position.width, position.height), scrollviewPosition, new Rect(0, 0, position.width - 30, scrollviewHeight)); GUI.skin = old; for (int i = 0; i < hotbarObjects.Count; ++i) { if (hotbarObjects[i] == null) { hotbarObjects.RemoveAt(i); --i; widgetHost.WidgetsCount--; continue; } GUIContent cnt = new GUIContent(); Texture2D preview; hotbarPreviewCache.TryGetValue(hotbarObjects[i], out preview); if (preview != null) cnt.image = preview; else cnt.image = AssetDatabase.GetCachedIcon(AssetDatabase.GetAssetPath(hotbarObjects[i])); if(useTooltip) cnt.tooltip = hotbarObjects[i].name; Rect r = widgetHost.Widgets[i]; //object selection if (e.rawType == EventType.MouseDown) { if (r.Contains(e.mousePosition)) { //Drag object if (e.button == 0) { if (e.clickCount != 2) { selectedObj = hotbarObjects[i]; DragAndDrop.PrepareStartDrag(); string path = AssetDatabase.GetAssetPath(selectedObj); if (path != "") DragAndDrop.paths = new string[] { path }; if (selectedObj != null) DragAndDrop.objectReferences = new Object[] { selectedObj }; DragAndDrop.StartDrag(selectedObj.ToString()); e.Use(); } else if (e.clickCount == 2) { if (hotbarObjects[i].GetType() == EditorPlus.EPlusDefaultType) { string path = AssetDatabase.GetAssetPath(Selection.activeObject); if (Directory.Exists(path)) { string[] subFolders = Directory.GetDirectories(path); if (subFolders.Length != 0) { AssetDatabase.OpenAsset(AssetDatabase.LoadMainAssetAtPath(subFolders[0])); break; } string[] content = Directory.GetFiles(path); if(content.Length == 0) { AssetDatabase.OpenAsset(hotbarObjects[i]); } else { foreach(string file in content) { Object asset = AssetDatabase.LoadMainAssetAtPath(file); if(asset != null) { EditorGUIUtility.PingObject(asset); break; } } } } else { if (hotbarObjects[i].ToString().Contains("SceneAsset")) //deselect to prevent annoying merge warnings Selection.activeObject = null; AssetDatabase.OpenAsset(hotbarObjects[i]); } } else { AssetDatabase.OpenAsset(hotbarObjects[i]); } } } else if (e.button == 1) { hotbarPreviewCache.Remove(hotbarObjects[i]); hotbarObjects.RemoveAt(i); --i; GUI.EndScrollView(); Repaint(); e.Use(); return; } hoverSelected = true; } } else if (e.rawType == EventType.MouseUp && r.Contains(e.mousePosition)) hoverSelected = true; GUI.Label(r, cnt, (selectedObj != hotbarObjects[i]) ? new GUIStyle(GUI.skin.button) : new GUIStyle(GUI.skin.box)); int limit = textLimit; if (limit >= hotbarObjects[i].name.Length) limit = hotbarObjects[i].name.Length; cnt = new GUIContent(hotbarObjects[i].name.Substring(0, limit)); if(cnt.text.Length > textLimit) { cnt.text.Remove(cnt.text.Length - 1, 1); } r.height = 20f; //drop shadow GUIStyle st = new GUIStyle(GUI.skin.label); st.normal.textColor = new Color(0.26f, 0.26f, 0.26f); r.x += 1f; r.y += 1f; GUI.Label(r, cnt, st); //reset r.x -= 1f; r.y -= 1f; //name GUI.Label(r, cnt); } GUI.EndScrollView(); if (e.rawType == EventType.MouseUp && DragAndDrop.objectReferences != null) { DragAndDrop.PrepareStartDrag(); } if (insideWindow && !hoverSelected && e.rawType == EventType.MouseUp) { selectedObj = null; Selection.activeObject = null; } }
private void StartLoading() { Configuration.Instance.Deserilized = false; //Configuration.Instance.Initialized = false; #if DEBUG if (DebugMode) Debug.Log("ConfigLoader: loading configuration."); #endif if (AsyncMode) { var url = UnityEngine.Application.isEditor ? EditorConfigUrl : ConfigUrl; #if DEBUG if (DebugMode) Debug.Log(string.Format("ConfigLoader: loading in Async mode [{0}]", url)); #endif _connector = new HttpConnector { Url = url, CacheBuster = CacheBuster, FaultHandler = OnAsyncFault, ResponseMode = ResponseMode.WWW, Timeout = 30, //LogCalls = true }; _connector.Send(new Responder(OnAsyncResult)); } else { #if DEBUG if (DebugMode) Debug.Log(string.Format("ConfigLoader: loading from Resources [{0}]", ConfigPath)); #endif _config = Resources.Load(ConfigPath); if (null == _config) { string msg = string.Format(ConfigurationException.LoadingError); #if DEBUG if (DebugMode) Debug.Log(msg); #endif //Alert.Show(msg, "Configuration error"); if (null != ResultHandler) ResultHandler(msg); } else { Configuration.Instance.ProcessConfig(_config.ToString()); if (null != ResultHandler) ResultHandler(Configuration.Instance.Application); } } }