Example #1
0
 //This returns an array of each line in that config file
 public static string[] GetPlayersConfig()
 {
     if (CheckFile(Item.PlayerConfig))
     {
         string file = File.ReadAllText(GetCurrentDirectory() + folderConfig + filePlayerConfig);
         return(file.Split('\n'));
     }
     else
     {
         CustomDebug.Log(CustomDebug.Type.Warning, "File for players config doesn't exist");
         return(new string[0]);
     }
 }
Example #2
0
    public static int GetIntValueFromConfig(string settingName)
    {
        int    value;
        string sValue = GetSettingFromConfig(settingName);

        if (!int.TryParse(sValue, out value))
        {
            value = -1;
            CustomDebug.Log(CustomDebug.Type.Error, string.Format("Could not convert {0}'s value of {1} to a int", settingName, sValue));
        }

        return(value); //This will return -1 if it fails
    }
Example #3
0
    public static void UpdateNestedPrefabsInGameobject(GameObject root)
    {
        NestedPrefab[] nestedObjects = Resources.FindObjectsOfTypeAll <NestedPrefab>();

        List <NestedPrefab> nestedPrefabsForReplace = new List <NestedPrefab>();

        root.FindComponentsInChildren <NestedPrefab>(ref nestedPrefabsForReplace);

        Dictionary <string, GameObject> nestedDictionary = CollectNestedDictionary(nestedObjects, nestedPrefabsForReplace);
        List <GameObject> objectsForRemove = new List <GameObject>();

        GameObject prefab = PrefabUtility.FindPrefabRoot(root);

        if (PrefabUtility.GetPrefabType(prefab) == PrefabType.Prefab)
        {
            GameObject     newInstance        = PrefabUtility.InstantiatePrefab(prefab) as GameObject;
            NestedPrefab[] childNestedPrefabs = newInstance.GetComponentsInChildren <NestedPrefab>();

            foreach (NestedPrefab childInstance in childNestedPrefabs)
            {
                CustomDebug.Log("Updated  " + childInstance.name + "  in  " + prefab.name);

                objectsForRemove.Add(childInstance.gameObject);
                ReplaceGameobject(childInstance.gameObject, nestedDictionary[childInstance.prefabGuid]);
                DestroyImmediate(childInstance);
            }

            objectsForRemove.ForEach(DestroyImmediate);
            objectsForRemove.Clear();

            PrefabUtility.ReplacePrefab(newInstance, prefab);
            DestroyImmediate(newInstance);
        }
        else if (PrefabUtility.GetPrefabType(prefab) == PrefabType.PrefabInstance)
        {
            foreach (NestedPrefab childInstance in nestedPrefabsForReplace)
            {
                CustomDebug.Log("Updated  " + childInstance.name + "  in  " + prefab.name);

                objectsForRemove.Add(childInstance.gameObject);
                ReplaceGameobject(childInstance.gameObject, nestedDictionary[childInstance.prefabGuid]);
                DestroyImmediate(childInstance);
            }
            objectsForRemove.ForEach(DestroyImmediate);
            objectsForRemove.Clear();
        }
        else
        {
            CustomDebug.Log(prefab.name + " : prefab is broken");
        }
    }
Example #4
0
    static void SaveAsset(T obj)
    {
        string defaultAssetPath = "Assets/Resources/" + FileName + ".asset";
        string dirName          = Path.GetDirectoryName(defaultAssetPath);

        if (!Directory.Exists(dirName))
        {
            Directory.CreateDirectory(dirName);
        }
        AssetDatabase.CreateAsset(obj, defaultAssetPath);
        AssetDatabase.SaveAssets();

        CustomDebug.Log("Saved " + FileName + " instance");
    }
Example #5
0
    /// <summary>
    /// Reads data from the persistent path as per given filename
    /// returns empty string if no file exists
    /// </summary>
    /// <param name="fileName">filename from which we want to read data</param>
    /// <returns></returns>
    public static string GetDataFromPersistentFile(string fileName)
    {
        string filePath = GetPersistentPath(fileName);

        if (File.Exists(filePath))
        {
            return(File.ReadAllText(filePath));
        }
        else
        {
            CustomDebug.Log("Trying to read file which does not exist returning empty string");
            return(string.Empty);
        }
    }
Example #6
0
    void Start()
    {
        if (uiCamera != null)
        {
            CustomDebug.Log("It is no longer necessary to hook up a camera to the tk2dUIManager. You can simply attach a tk2dUICamera script to the cameras that interact with UI.");
            HookUpLegacyCamera(uiCamera);
            uiCamera = null;
        }

        if (allCameras.Count == 0)
        {
            CustomDebug.LogError("Unable to find any tk2dUICameras, and no cameras are connected to the tk2dUIManager. You will not be able to interact with the UI.");
        }
    }
Example #7
0
    public static void RebuildIndex()
    {
        EditorUtility.DisplayProgressBar("Texture Manager", "scanning for collections...", 0);

        collections = AssetUtility.GetAssetsAtPath <tmTextureCollection>("TextureManagmentCollections");

        EditorUtility.DisplayProgressBar("Texture Manager", "collections founded : " + collections.Count, 1);
        System.Threading.Thread.Sleep(500);

        tmIndex.Instance.TextureCollections.Clear();
        tmIndex.Instance.TexturePlatformCollections.Clear();

        int current = 0;

        for (int i = 0; i < collections.Count; i++)
        {
            tmTextureCollection collection = collections[i];

            if (!collection.IsNull())
            {
                CustomDebug.Log("Rebuild collection : " + collection.name);

                try
                {
                    EditorUtility.DisplayProgressBar("Texture Manager", "building : " + collection.name, current++ *1f / collections.Count);

                    tmCollectionBuilder.BuildCollection(collection);

                    Resources.UnloadUnusedAssets();
                    System.GC.Collect();
                }
                catch (System.Exception ex)
                {
                    CustomDebug.Log(ex);
                }
            }
        }

        EditorUtility.SetDirty(tmIndex.Instance);
//		tmCollectionBuilder.ValidateResourceLinks();

        AssetDatabase.SaveAssets();
        AssetDatabase.Refresh();

        collections.Clear();
        EditorUtility.ClearProgressBar();

        Resources.UnloadUnusedAssets();
        System.GC.Collect();
    }
        public static void SerializeTest <T>(T obj)
        {
            string str = MiniJSON.Json.Serialize(obj);

            CustomDebug.Log(str);
            T t = MiniJSON.Json.Deserialize <T>(str);

            CustomDebug.Log(t);
            CustomDebug.Log(t.GetType());

            string str2 = MiniJSON.Json.Serialize(t);

            CustomDebug.Log(str2);
        }
Example #9
0
 /// <summary>
 /// Saves data in persistent path as per given file name
 /// </summary>
 /// <param name="fileName">File name in which we want to save data</param>
 /// <param name="data">Data which we want to save</param>
 public static void SaveToPersistentFile(string fileName, string data)
 {
     try
     {
         CustomDebug.Log("Saving data to file : " + GetPersistentPath(fileName));
         File.WriteAllText(GetPersistentPath(fileName), data);
         "Data Saved".ShowAsAlert();
     }
     catch (Exception ex)
     {
         CustomDebug.LogException("Custom exception while saving data : " + ex.Message + " to file named " + fileName);
         ex.Message.ShowAsAlert();
     }
 }
Example #10
0
//		private T Convert<T>( PBXDictionary dictionary )
//		{
//			if( dictionary.ContainsKey( "isa" ) ){
////				((string)dictionary["isa"]).CompareTo(
//				Type targetType = Type.GetType( (string)dictionary["isa"] );
//				if( targetType.IsSubclassOf( typeof(PBXObject) ) ) {
//					Debug.Log( "ok" );
//					T converted = (T)Activator.CreateInstance( targetType );
//					return converted;
//				}
//				else {
//					Debug.Log( "Warning: unknown PBX type: " + targetType.Name );
//					return default(T);
//				}
//
//			}
//			return default(T);
//
//		}

        private PBXDictionary ParseDictionary()
        {
            SkipWhitespaces();
            PBXDictionary dictionary  = new PBXDictionary();
            string        keyString   = string.Empty;
            object        valueObject = null;

            bool complete = false;

            while (!complete)
            {
                switch (NextToken())
                {
                case END_OF_FILE:
                    CustomDebug.Log("Error: reached end of file inside a dictionary: " + index);
                    complete = true;
                    break;

                case DICTIONARY_ITEM_DELIMITER_TOKEN:
                    keyString   = string.Empty;
                    valueObject = null;
                    break;

                case DICTIONARY_END_TOKEN:
                    keyString   = string.Empty;
                    valueObject = null;
                    complete    = true;
                    break;

                case DICTIONARY_ASSIGN_TOKEN:
                    if (!dictionary.ContainsKey(keyString))
                    {
                        valueObject = ParseValue();
                        dictionary.Add(keyString, valueObject);
                    }
                    else
                    {
                        CustomDebug.LogError("ParseDictionary , keys allready exist = " + keyString);
                    }
                    break;

                default:
                    StepBackward();
                    keyString = ParseValue() as string;
                    break;
                }
            }
            return(dictionary);
        }
    // Fix up upgraded data structures
    public void Upgrade()
    {
        if (version == CURRENT_VERSION)
        {
            return;
        }

        CustomDebug.Log("SpriteCollection '" + this.name + "' - Upgraded from version " + version.ToString());

        if (version == 0)
        {
            if (pixelPerfectPointSampled)
            {
                filterMode = FilterMode.Point;
            }
            else
            {
                filterMode = FilterMode.Bilinear;
            }

            // don't bother messing about with user settings
            // on old atlases
            userDefinedTextureSettings = true;
        }

        if (version < 3)
        {
            if (textureRefs != null && textureParams != null && textureRefs.Length == textureParams.Length)
            {
                for (int i = 0; i < textureRefs.Length; ++i)
                {
                    textureParams[i].texture = textureRefs[i];
                }

                textureRefs = null;
            }
        }

        if (version < 4)
        {
            sizeDef.CopyFromLegacy(useTk2dCamera, targetOrthoSize, targetHeight);
        }

        version = CURRENT_VERSION;

#if UNITY_EDITOR
        UnityEditor.EditorUtility.SetDirty(this);
#endif
    }
    static void CheckNestedPrefabs()
    {
        List <GameObject> duplicates = new List <GameObject>();

        CollectGUIDMap(".prefab", duplicates);

        if (duplicates.Count > 0)
        {
            Selection.objects = duplicates.ToArray();
        }
        else
        {
            CustomDebug.Log("No duplicated GUID found");
        }
    }
Example #13
0
    public static void SplitMesh(Mesh mesh)
    {
        for (int i = 0; i < mesh.subMeshCount; i++)
        {
            string name = mesh.name + "_" + i;

            string assetPath = AssetDatabase.GetAssetPath(mesh);
            Mesh   newMesh   = MeshFromSubmesh(mesh, i);
            newMesh.name = name;

            CustomDebug.Log("add to : " + assetPath);
            AssetDatabase.AddObjectToAsset(newMesh, assetPath);
            AssetDatabase.Refresh();
        }
    }
Example #14
0
//		public bool success;
//		private int indent;

        public PBXDictionary Decode(string data)
        {
//			success = true;
            if (!data.StartsWith(PBX_HEADER_TOKEN))
            {
                CustomDebug.Log("Wrong file format.");
                return(null);
            }

            data      = data.Substring(13);
            this.data = data.ToCharArray();
            index     = 0;

            return((PBXDictionary)ParseValue());
        }
Example #15
0
 // Called by button in scene
 public void PauseButtonClicked()
 {
     CustomDebug.Log("[InGameGui]Pause Button Pressed", CustomDebug.Users.System, CustomDebug.Level.Trace);
     MenuTween.Toggle();
     if (Time.timeScale > 0)
     {
         Time.timeScale = 0;
         PauseMenu.SetActive(true);
     }
     else
     {
         StartCoroutine("SetMenuUnactive");
         Time.timeScale = 1;
     }
 }
    public void Upgrade()
    {
        if (version >= CURRENT_VERSION)
        {
            return;
        }
        CustomDebug.Log("Font '" + this.name + "' - Upgraded from version " + version.ToString());

        if (version == 0)
        {
            sizeDef.CopyFromLegacy(useTk2dCamera, targetOrthoSize, targetHeight);
        }

        version = CURRENT_VERSION;
    }
    public static Material SharedMaterial(Material matForCheck)
    {
        List <Material> materials = AssetUtility.GetAssetsAtPath <Material>(MATERIAL_SUB_PATH);

        foreach (Material mat in materials)
        {
            if (mat.shader == matForCheck.shader)
            {
                int  propertyCount    = ShaderUtil.GetPropertyCount(matForCheck.shader);
                bool propertiesEquals = true;

                for (int i = 0; i < propertyCount && propertiesEquals; i++)
                {
                    bool equal = CompareProperty(mat, matForCheck, i);
                    propertiesEquals &= equal;
                }

                if (propertiesEquals)
                {
                    return(mat);
                }
            }
        }

        string path = MATERIAL_SUB_PATH + matForCheck.name + ".mat";

        Material existMat = AssetDatabase.LoadAssetAtPath(path, typeof(Material)) as Material;

        if (existMat != null)
        {
            CustomDebug.Log("Material with the same name already exist!");
            return(existMat);
        }

        Material newMat = Object.Instantiate(matForCheck) as Material;

        newMat.name = matForCheck.name;

        AssetDatabase.CreateAsset(newMat, path);
        AssetDatabase.Refresh();
        AssetDatabase.SaveAssets();

        CustomDebug.Log("New material created: " + path);

        newMat = AssetDatabase.LoadAssetAtPath(path, typeof(Material)) as Material;

        return(newMat);
    }
Example #18
0
    // outputs the content of a 2D array, useful for checking the importer
    static public void DebugOutputGrid(string[,] grid)
    {
        for (int y = 0; y < grid.GetUpperBound(1); y++)
        {
            if (!string.IsNullOrEmpty(grid[0, y]))
            {
                string output = "";
                for (int x = 0; x < grid.GetUpperBound(0); x++)
                {
                    output += grid[x, y] + ", ";
                }

                CustomDebug.Log(output, DebugGroup.Editor);
            }
        }
    }
Example #19
0
 protected override bool Execute()
 {
     CustomDebug.Log("Execute Connexion", VerboseLevel.ALL);
     clientId = serverInformations.server.CreateNewClient(actualClient);
     if (clientId != -1)
     {
         serverInformations.server.SendData(actualClient, new AcceptConnexionData(serverInformations.world.worldGeneration, clientId));
         CustomDebug.Log("Client " + actualClient.Address.ToString() + ":" + actualClient.Port.ToString() + " connected", VerboseLevel.IMPORTANT);
         return(true);
     }
     else
     {
         CustomDebug.Log("Cant connect client " + actualClient.Address.ToString() + ":" + actualClient.Port.ToString(), VerboseLevel.IMPORTANT);
         return(false);
     }
 }
Example #20
0
    public static Dictionary <string, GameObject> CollectNestedDictionary(NestedPrefab[] allNestedObjects, List <NestedPrefab> nestedPrefabsForSearch)
    {
        Dictionary <string, GameObject> nestedDictionary = new Dictionary <string, GameObject>();

        foreach (NestedPrefab nestedCurrent in nestedPrefabsForSearch)
        {
            if (!nestedDictionary.ContainsKey(nestedCurrent.prefabGuid))
            {
                // find prefabs for selected
                foreach (NestedPrefab np in allNestedObjects)
                {
                    GameObject gameobject = np.gameObject;

                    if (PrefabUtility.GetPrefabType(gameobject) == PrefabType.Prefab && PrefabUtility.FindPrefabRoot(gameobject) == gameobject)
                    {
                        NestedPrefab nestedSource = gameobject.GetComponent <NestedPrefab>();
                        if (nestedSource != null)
                        {
                            if (nestedSource.prefabGuid == nestedCurrent.prefabGuid)
                            {
                                if (!nestedDictionary.ContainsKey(nestedSource.prefabGuid))
                                {
                                    nestedDictionary.Add(nestedSource.prefabGuid, nestedSource.gameObject);
                                }
                                else
                                {
                                    CustomDebug.LogError("Duplicate GUID : " + nestedSource.gameObject + "  +  " + nestedDictionary[nestedSource.prefabGuid] + " -> Solution : дать леща");
                                }
                            }
                        }
                        else
                        {
                            CustomDebug.Log("NestedPrefab component missing");
                        }
                    }
                }


                if (!nestedDictionary.ContainsKey(nestedCurrent.prefabGuid))
                {
                    CustomDebug.LogError("can't find prefab for " + nestedCurrent.name);
                }
            }
        }

        return(nestedDictionary);
    }
Example #21
0
        public static void takeDamage(int dmg)
        {
            if (dmg < 0)
            {
                CustomDebug.Log("[HealtStatic] don't try negative damage. Use addHealth instead", CustomDebug.Users.System, CustomDebug.Level.Warn);
                return;
            }

            if (health > dmg)
            {
                health -= dmg;
            }
            else
            {
                dead = true;
            }
        }
 // Use Async method
 public override void Load()
 {
     if (!IsLoaded)
     {
         loadedWWW = new WWW(CachedWWWStreamingAssetPath);
         while (!loadedWWW.isDone)
         {
             System.Threading.Thread.Sleep(1);
         }
         if (!string.IsNullOrEmpty(loadedWWW.error))
         {
             CustomDebug.Log("AssetLink Error WWW :: " + loadedWWW.error);
             loadedWWW.Dispose();
             loadedWWW = null;
         }
     }
 }
Example #23
0
        public static void addHealth(int heal)
        {
            if (heal < 0)
            {
                CustomDebug.Log("[HealtStatic] don't use negative healing. Use takeDamage instead", CustomDebug.Users.System, CustomDebug.Level.Warn);
                return;
            }

            if (health + heal > maxHealth)
            {
                health = maxHealth;
            }
            else if (health + heal < maxHealth)
            {
                health += heal;
            }
        }
Example #24
0
    private void onFlipCard(CardControl control)
    {
        if (curFlipCard == null)
        {
            curFlipCard = control;
            curFlipCard.Flip();
            roundStateEnum = RoundStateEnum.FlipAnimal;
            chooseTime     = 0;

            // 如果是 驴,需要从银行各发[100]给玩家
            if (curFlipCard.cardData.GetData <Animals>().Id == RoomData.SendCoinCardId)
            {
                sendCoinForDonkey();
                sendCardControl.MoveCardPosEnum(curFlipCard.cardData.UUID, RoomCardPosEnum.WillDestroy);
                curFlipCard = null;
                nextRound();
                return;
            }

            List <PlayerControl> hasSameAnimalPlayers = getSameAnimalPlayers();
            if (hasSameAnimalPlayers.Count == 0)
            {
                curSaleEnum = SaleCardEnum.SaleAnimal;
            }
            else
            {
                // TODO 需要做成玩家选择使用那种方式拍卖
                curSaleEnum = Random.value < 0.5f ? SaleCardEnum.SaleAnimal : SaleCardEnum.BehindBusiness;
            }
            CustomDebug.Log("准备拍卖模式:" + curSaleEnum.ToString());
            if (curSaleEnum == SaleCardEnum.BehindBusiness)
            {
                behindBusinessPlayer = hasSameAnimalPlayers[Random.Range(0, hasSameAnimalPlayers.Count)];
            }
            else
            {
                // 通知其他玩家出价
                RoomData.CurBidPrice = 0;
                SignalManager.Instance.Create <NotifyBidSignal>().Dispatch();
            }
        }
        else
        {
            Debug.LogWarning("本回合已翻牌,无法继续翻牌");
        }
    }
Example #25
0
    void UIManager_OnPauseRequest()
    {
        if (this == null)
        {
            return;
        }

        if (willsend)
        {
            Invoke("pausepause", Random.Range(0.2f, 2f));
        }
        else
        {
            CustomDebug.Log("No pause", CustomDebug.Level.Info);
        }
        willsend = !willsend;
    }
Example #26
0
        public static void SetDifficulty()
        {
            CustomDebug.Log("[ScoreStatics] Setting difficulty to : " + diff, CustomDebug.Users.System, CustomDebug.Level.Trace);
            switch (diff)
            {
            case diffLevels.Easy:
                baseMulti = 10;
                break;

            case diffLevels.Normal:
                baseMulti = 12;
                break;

            case diffLevels.Hard:
                baseMulti = 15;
                break;
            }
        }
    public static string GUIDToAssetPath(string guid)
    {
        string path = string.Empty;

        #if UNITY_EDITOR
        path = AssetDatabase.GUIDToAssetPath(guid);
        #else
        if (!isParse)
        {
            Parse();
        }
        if (!guidMap.TryGetValue(guid, out path))
        {
            CustomDebug.Log("GUIDMapper.Log can't find path for Guid : " + guid);
        }
        #endif
        return(path);
    }
Example #28
0
    public void LoadPlayersConfig()
    {
        settings.Clear();
        List <Setting> playerSettings = FileManager.GetPlayersConfigAsSettings();

        //This is to check if the players config wasn't already created
        if (playerSettings.Count == 0)
        {
            CustomDebug.Log(CustomDebug.Type.Log, "Loading Default Settings");
            LoadDefaultSettings();
            return;
        }
        foreach (Setting setting in playerSettings)
        {
            settings.Add(setting);
        }
        ReloadUI();
    }
Example #29
0
    IEnumerator WaitPause()
    {
        if (!pauseopen)
        {
            pauseopen = true;
            StartCoroutine(OpenPause());

            PauseText.text = "Waiting for Response";
            int length = 300;
            for (int i = 0; i < length; i++)
            {
                if (PauseReceivedCallback)
                {
                    break;
                }

                if (i % 12 == 0)
                {
                    PauseText.text = "." + PauseText.text + ".";
                }
                if (i % 48 == 0)
                {
                    PauseText.text = "Waiting for Response";
                }
                yield return(new WaitForEndOfFrame());
            }
            if (!PauseReceivedCallback)
            {
                PauseText.text = "No response";
                yield return(new WaitForSeconds(0.9f));

                StartCoroutine("ClosePause");
                CustomDebug.Log("Did not recieve");
            }
            else
            {
                PauseText.text = "Paused";
                CustomDebug.Log("Paused");
            }
            PauseReceivedCallback = false;
            // pauseopen = false;
        }
        yield return(new WaitForEndOfFrame());
    }
Example #30
0
        public static void AddScore(int amount)
        {
            CustomDebug.Log("[ScoreStatics] Before adding is " + Score, CustomDebug.Users.Jesse, CustomDebug.Level.Trace);
            if (!Bonus)
            {
                Score += Mathf.FloorToInt(amount * (baseMulti / 10f));
            }
            else
            {
                Score += Mathf.FloorToInt((amount * (baseMulti / 10f)) * 2);
            }

            if (Score > HighScore)
            {
                HighScore = Score;
            }

            CustomDebug.Log("[ScoreStatics] New Score is " + Score, CustomDebug.Users.Jesse, CustomDebug.Level.Trace);
        }