public static tk2dSpriteCollectionData GetDefaultSpriteCollection()
    {
        BuildLookupIndex(false);

        foreach (tk2dSpriteCollectionIndex indexEntry in allSpriteCollections)
        {
            if (!indexEntry.managedSpriteCollection && indexEntry.spriteNames != null)
            {
                foreach (string name in indexEntry.spriteNames)
                {
                    if (name != null && name.Length > 0)
                    {
                        GameObject scgo = AssetDatabase.LoadAssetAtPath(AssetDatabase.GUIDToAssetPath(indexEntry.spriteCollectionDataGUID), typeof(GameObject)) as GameObject;
                        if (scgo != null)
                        {
                            return(scgo.GetComponent <tk2dSpriteCollectionData>());
                        }
                    }
                }
            }
        }

        CustomDebug.LogError("Unable to find any sprite collections.");
        return(null);
    }
示例#2
0
        private PBXList ParseArray()
        {
            PBXList list     = new PBXList();
            bool    complete = false;

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

                case ARRAY_END_TOKEN:
                    complete = true;
                    break;

                case ARRAY_ITEM_DELIMITER_TOKEN:
                    break;

                default:
                    StepBackward();
                    list.Add(ParseValue());
                    break;
                }
            }
            return(list);
        }
示例#3
0
 /// <summary>
 /// Copies the source animation clip into the current one.
 /// All frames are duplicated.
 /// </summary>
 public void CopyFrom(tk2dSpriteAnimationClip source)
 {
     name = source.name;
     if (source.frames == null)
     {
         frames = null;
     }
     else
     {
         frames = new tk2dSpriteAnimationFrame[source.frames.Length];
         for (int i = 0; i < frames.Length; ++i)
         {
             if (source.frames[i] == null)
             {
                 frames[i] = null;
             }
             else
             {
                 frames[i] = new tk2dSpriteAnimationFrame();
                 frames[i].CopyFrom(source.frames[i]);
             }
         }
     }
     fps       = source.fps;
     loopStart = source.loopStart;
     wrapMode  = source.wrapMode;
     if (wrapMode == tk2dSpriteAnimationClip.WrapMode.Single && frames.Length > 1)
     {
         frames = new tk2dSpriteAnimationFrame[] { frames[0] };
         CustomDebug.LogError(string.Format("Clip: '{0}' Fixed up frames for WrapMode.Single", name));
     }
 }
示例#4
0
        public override void EnterState()
        {
            CustomDebug.LogMessage("Dead enter!", DebugColor.green);
            ICommand deadCMD = new DeadAnimationCommand(owner, GetType());

            deadCMD.Execute();
        }
示例#5
0
    public void open(int arg)
    {
        if (current == arg)
        {
            CustomDebug.Log("Menu Tried to open self", CustomDebug.Level.Warn);
            return;
        }
        else
        {
            CustomDebug.Log("Opened menu no: " + arg);

            if (arg != 0 && current != 0)
            {
                StartCoroutine(openAMenu(arg));
            }
            else if (current == 0)
            {
                StartCoroutine(openFromMain(arg));
            }
            else if (arg == 0)
            {
                StartCoroutine(openMain());
            }
            else
            {
                CustomDebug.Log("something weard happend", CustomDebug.Level.Warn);
            }
        }
    }
示例#6
0
	/// <summary>
	/// Makes the text mesh pixel perfect to the active camera.
	/// Automatically detects <see cref="tk2dCamera"/> if present
	/// Otherwise uses Camera.main
	/// </summary>
	public void MakePixelPerfect()
	{
		float s = 1.0f;
		tk2dCamera cam = tk2dCamera.CameraForLayer(gameObject.layer);
		if (cam != null)
		{
			if (FontInst.version < 1)
			{
				CustomDebug.LogError("Need to rebuild font.");
			}

			float zdist = (transform.position.z - cam.transform.position.z);
			float textMeshSize = (FontInst.invOrthoSize * FontInst.halfTargetHeight);
			s = cam.GetSizeAtDistance(zdist) * textMeshSize;
		}
		else if (Camera.main)
		{
#if UNITY_5
			if (Camera.main.orthographic)
#else
			if (Camera.main.isOrthoGraphic)
#endif

			{
				s = Camera.main.orthographicSize;
			}
			else
			{
				float zdist = (transform.position.z - Camera.main.transform.position.z);
				s = tk2dPixelPerfectHelper.CalculateScaleForPerspectiveCamera(Camera.main.fieldOfView, zdist);
			}
			s *= FontInst.invOrthoSize;
		}
		scale = new Vector3(Mathf.Sign(scale.x) * s, Mathf.Sign(scale.y) * s, Mathf.Sign(scale.z) * s);
	}	
    /// <summary>
    /// Internal function to make sure all material Ids are valid. Used in the tilemap editor
    /// </summary>
    public void InitMaterialIds()
    {
        if (inst.materialIdsValid)
        {
            return;
        }

        int firstValidIndex = -1;
        Dictionary <Material, int> materialLookupDict = new Dictionary <Material, int>();

        for (int i = 0; i < inst.materials.Length; ++i)
        {
            if (firstValidIndex == -1 && inst.materials[i] != null)
            {
                firstValidIndex = i;
            }
            materialLookupDict[materials[i]] = i;
        }
        if (firstValidIndex == -1)
        {
            CustomDebug.LogError("Init material ids failed.");
        }
        else
        {
            foreach (var v in inst.spriteDefinitions)
            {
                if (!materialLookupDict.TryGetValue(v.material, out v.materialId))
                {
                    v.materialId = firstValidIndex;
                }
            }
            inst.materialIdsValid = true;
        }
    }
示例#8
0
    protected override void Awake()
    {
        base.Awake();
        gameObject.GetComponentsInChildren <ObjectPool>(pools);

                #if UNITY_EDITOR
        pools.Sort
        (
            (a, b) => string.CompareOrdinal(a.name, b.name)
        );
                #endif

        foreach (ObjectPool pool in pools)
        {
            if (pool.prefab == null)
            {
                CustomDebug.LogError("Missing prefab in pool : " + pool.name, pool);
            }
            else
            {
                if (!poolMap.ContainsKey(pool.prefab.name))
                {
                    poolMap.Add(pool.prefab.name, pool);
                }
                else
                {
                    CustomDebug.LogError("Duplicate : " + pool.prefab.name, pool);
                }
            }
        }
    }
    protected virtual void HideTweenData(bool immediately, float delay)
    {
        for (int i = 0, n = tweensData.Count; i < n; i++)
        {
            TweenData t = tweensData[i];

            if (t != null)
            {
                if (t.tween == null)
                {
                    CustomDebug.LogError(gameObject.name + ": Tween on GUIControl component not set!", this);
                }
                else
                {
                    if (immediately)
                    {
                        t.tween.SetBeginStateImmediately();
                        t.tween.enabled = false;
                    }
                    else
                    {
                        t.tween.scaleDuration = t.hideDurationScale;
                        t.tween.SetBeginState(t.hideDelay + Random.Range(-t.showDelayVariance * 0.5f, t.showDelayVariance * 0.5f) + delay);
                    }
                }
            }
        }
    }
示例#10
0
        public static void GetLoopOrder(tk2dTileMapData.SortMethod sortMethod, int w, int h, out int x0, out int x1, out int dx, out int y0, out int y1, out int dy)
        {
            switch (sortMethod)
            {
            case tk2dTileMapData.SortMethod.BottomLeft:
                x0 = 0; x1 = w; dx = 1;
                y0 = 0; y1 = h; dy = 1;
                break;

            case tk2dTileMapData.SortMethod.BottomRight:
                x0 = w - 1; x1 = -1; dx = -1;
                y0 = 0; y1 = h; dy = 1;
                break;

            case tk2dTileMapData.SortMethod.TopLeft:
                x0 = 0; x1 = w; dx = 1;
                y0 = h - 1; y1 = -1; dy = -1;
                break;

            case tk2dTileMapData.SortMethod.TopRight:
                x0 = w - 1; x1 = -1; dx = -1;
                y0 = h - 1; y1 = -1; dy = -1;
                break;

            default:
                CustomDebug.LogError("Unhandled sort method");
                goto case tk2dTileMapData.SortMethod.BottomLeft;
            }
        }
示例#11
0
        internal void Update()
        {
            for (var i = 0; i < _chains.Count; i++)
            {
                AsyncChain chain = _chains[i];
                ChainLayer layer = _chainsLayers[(int)chain.layer];
                if (layer.paused)
                {
                    continue;
                }
                AsyncCommandResult updateResult = chain.UpdateChain();

                if (updateResult == AsyncCommandResult.Exception)
                {
                    CustomDebug.Log($"Cain '{chain.id}' finished terminated with exception");
                }

                if (!chain.isComplete && updateResult == AsyncCommandResult.Ok)
                {
                    continue;
                }
                chain.ReportComplete();
                _chainsLayers[(int)chain.layer].Dec();
                _chains.RemoveAt(i);
                i--;
            }
        }
示例#12
0
 private void killAction()
 {
     if (!SlimeDead_)
     {
         if (animator != null)
         {
             animator.SetTrigger("FinalHit");
             Destroy(animator.gameObject, privateWaitTime);
             if (!SlimeDead && (slimeInfo.particleEffect != null))
             {
                 CustomDebug.Log("[Slime]killAction type:" + slimeInfo.slimeType, CustomDebug.Users.System, CustomDebug.Level.Trace);
                 if (slimeInfo.slimeType == SlimeType.Bomb)
                 {
                     StartCoroutine(InstantiateDelay(slimeInfo.particleEffect, 0.25f));
                 }
                 else if (slimeInfo.slimeType == SlimeType.Pinata)
                 {
                     StartCoroutine(InstantiateDelay(slimeInfo.particleEffect, 0.2f));
                 }
                 else
                 {
                     GameObject.Instantiate(slimeInfo.particleEffect, transform.position, Quaternion.identity);
                 }
             }
         }
         SlimeDead_ = true;
         hp         = 0;
         ParentScrip.currentActive--;
         gameData.ScoreStat.AddScore(5);
     }
 }
示例#13
0
        private void Awake()
        {
            _gameScenarioBase = FindObjectOfType <GameScenarioBase>();
            _gameProgress     = FindObjectOfType <GameProgress>();

            _nextSceneNumber = SceneManager.GetActiveScene().buildIndex + _nextLoadSceneNumber;
            if (_gameScenarioBase == null)
            {
                var scenario = CustomResources.Load <GameScenarioBase>
                                   (AssetsPathGameObject.GameObjects[GameObjectType.GameScenarioExecutor]);

                _gameScenarioBase = Instantiate(scenario);
                if (_gameScenarioBase == null)
                {
                    CustomDebug.LogError("GameScenarioExecutor has no scenario", this);
                    return;
                }
            }
            _gameScenarioBase.Inject(_gameProgress);

            Planner.Chain()
            .AddFunc(_gameScenarioBase.ExecuteScenario)
            .AddAction(LoadNextScene)
            ;
        }
示例#14
0
        public override void ExitState()
        {
            CustomDebug.LogMessage("Idle exit!", DebugColor.red);
            ICommand command = new ChangeAnimationCommand(owner, GetType());

            command.Execute();
        }
示例#15
0
    private static string[] GetSortingLayerNames()
    {
        if (sortingLayerNamesPropInfo == null && !sortingLayerNamesChecked)
        {
            sortingLayerNamesChecked = true;
            try {
                System.Type IEU = System.Type.GetType("UnityEditorInternal.InternalEditorUtility,UnityEditor");
                if (IEU != null)
                {
                    sortingLayerNamesPropInfo = IEU.GetProperty("sortingLayerNames", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.Public);
                }
            }
            catch { }
            if (sortingLayerNamesPropInfo == null)
            {
                CustomDebug.Log("tk2dEditorUtility - Unable to get sorting layer names.");
            }
        }

        if (sortingLayerNamesPropInfo != null)
        {
            return(sortingLayerNamesPropInfo.GetValue(null, null) as string[]);
        }
        else
        {
            return(new string[0]);
        }
    }
    /// <summary>
    /// Sets the reference to a poolable object with the specified component.
    /// </summary>
    /// <param name="componentOfPoolableObject">The component of the poolable object.</param>
    /// <param name="allowNonePoolable">If set to false an error is output if the object does not have the <see cref="PoolableObject"/> component.</param>
    public void Set(T componentOfPoolableObject, bool allowNonePoolable)
#endif
    {
        if (!componentOfPoolableObject)
        {
            Reset();
            return;
        }
        _objComponent = ( T )componentOfPoolableObject;
        _pooledObj    = _objComponent.GetComponent <PoolableObject>();
        if (!_pooledObj)
        {
            if (allowNonePoolable)
            {
                _initialUsageCount = 0;
            }
            else
            {
                CustomDebug.LogError("Object for PoolableReference must be poolable");
                return;
            }
        }
        else
        {
            _initialUsageCount = _pooledObj._usageCount;
        }
    }
        public static List <SerializedField> DiffFields(Object original, Object instance, System.Type attribute = null)
        {
            List <SerializedField> overrideFields = new List <SerializedField>();

            Dictionary <string, object> dict  = Serialization.SerializeUtility.FindFields(instance, attribute);
            Dictionary <string, object> dict2 = Serialization.SerializeUtility.FindFields(original, attribute);

            foreach (var pair in dict)
            {
                if (dict2.ContainsKey(pair.Key))
                {
                    string ser1 = JsonConvert.SerializeObject(pair.Value);
                    string ser2 = JsonConvert.SerializeObject(dict2[pair.Key]);

                    if (ser1 != ser2)
                    {
                        Serialization.SerializedField field = new Serialization.SerializedField();
                        field.field     = pair.Key;
                        field.jsonValue = MiniJSON.Json.Serialize(pair.Value);
                        overrideFields.Add(field);

                        CustomDebug.Log(pair.Key + " : " + pair.Value);
                    }
                }
            }

            return(overrideFields);
        }
 protected void Awake()
 {
     if (_myPool == null && !ObjectPoolController._isDuringInstantiate)
     {
         CustomDebug.LogWarning("Poolable object " + name + " was instantiated without ObjectPoolController");
     }
 }
示例#19
0
    tk2dUIItem RaycastForUIItem(Vector2 screenPos)
    {
        int cameraCount = sortedCameras.Count;

        for (int i = 0; i < cameraCount; ++i)
        {
            tk2dUICamera currCamera = sortedCameras[i];
            if (currCamera.RaycastType == tk2dUICamera.tk2dRaycastType.Physics3D)
            {
                ray = currCamera.HostCamera.ScreenPointToRay(screenPos);
                if (Physics.Raycast(ray, out hit, currCamera.HostCamera.farClipPlane - currCamera.HostCamera.nearClipPlane, currCamera.FilteredMask))
                {
                    return(hit.collider.GetComponent <tk2dUIItem>());
                }
            }
            else if (currCamera.RaycastType == tk2dUICamera.tk2dRaycastType.Physics2D)
            {
#if !(UNITY_3_5 || UNITY_4_0 || UNITY_4_0_1 || UNITY_4_1 || UNITY_4_2)
                Collider2D collider = Physics2D.OverlapPoint(currCamera.HostCamera.ScreenToWorldPoint(screenPos), currCamera.FilteredMask);
                if (collider != null)
                {
                    return(collider.GetComponent <tk2dUIItem>());
                }
#else
                CustomDebug.LogError("Physics2D only supported in Unity 4.3 and above");
#endif
            }
        }
        return(null);
    }
    /// <summary>
    /// Preloads as many instances to the pool so that there are at least as many as
    /// specified in <see cref="PoolableObject.preloadCount"/>.
    /// </summary>
    /// <param name="prefab">The prefab.</param>
    /// <remarks>
    /// Use ObjectPoolController.isDuringPreload to check if an object is preloaded in the <c>Awake()</c> function.
    /// If the pool already contains at least <see cref="PoolableObject.preloadCount"/> objects, the function does nothing.
    /// </remarks>
    /// <seealso cref="PoolableObject.preloadCount"/>
    static public void Preload(GameObject prefab)   // adds as many instances to the prefab pool as specified in the PoolableObject
    {
        PoolableObject poolObj = prefab.GetComponent <PoolableObject>();

        if (poolObj == null)
        {
            CustomDebug.LogWarning("Can not preload because prefab '" + prefab.name + "' is not poolable");
            return;
        }

        var pool = _GetPool(poolObj);   // _preloadDone is set by _GetPool

        int delta = poolObj.preloadCount - pool.GetObjectCount();

        if (delta <= 0)
        {
            return;
        }

        isDuringPreload = true;

        try
        {
            for (int i = 0; i < delta; i++)
            {
                pool.PreloadInstance();
            }
        }
        finally
        {
            isDuringPreload = false;
        }

        //Debug.Log( "preloaded: " + prefab.name + " " + poolObj.preloadCount + " times" );
    }
示例#21
0
 void InitHandlerObjects()
 {
     foreach (var obj in layoutHandlerObjects)
     {
         if (obj != null)
         {
             ILayoutCellHandler handler = obj.GetComponent <ILayoutCellHandler>();
             if (handler != null)
             {
                 if (!layoutHandlers.Contains(handler))
                 {
                     layoutHandlers.Add(handler);
                 }
             }
             else
             {
                 gameObject.name = CachedName + "(NOT_FOUND_HANDLERS)";
                 CustomDebug.LogWarning("no handlers found in GUILayoutCell references, gameObject name = " + CachedName, this);
             }
         }
         else
         {
             gameObject.name = CachedName + "(NOT_FOUND_HANDLERS)";
             CustomDebug.LogWarning("no handlers found in GUILayoutCell references, gameObject name = " + CachedName, this);
         }
     }
 }
示例#22
0
    IEnumerator Loading(string path)
    {
        WWW loader = new WWW(path);

        yield return(loader);

        state = TextureState.NotLoaded;

        if (loader.isDone)
        {
            if (string.IsNullOrEmpty(loader.error))
            {
                texture = loader.textureNonReadable;
                state   = TextureState.Loaded;
            }
            else
            {
                CustomDebug.LogError("Can't download texture by url : " + path + "\n" + loader.error);
            }
        }

        loader.Dispose();
        loading = null;

        if (!callbacks.Call(path, texture))
        {
            UnloadTexture();
        }
    }
示例#23
0
    // Deletes the asset from the global asset dictionary
    // and removes the associated the asset from the build
    public static bool UnmakeLoadableAsset(Object obj)
    {
        string guid = GetObjectGUID(obj);
        List <tk2dResourceTocEntry> toc = new List <tk2dResourceTocEntry>(tk2dSystem.inst.Editor__Toc);

        foreach (tk2dResourceTocEntry entry in toc)
        {
            if (entry.assetGUID == guid)
            {
                // Delete the corresponding resource object
                string resourceObjectPath = AssetDatabase.GUIDToAssetPath(entry.resourceGUID);
                AssetDatabase.DeleteAsset(resourceObjectPath);

                // remove from TOC
                toc.Remove(entry);
                break;
            }
        }

        if (tk2dSystem.inst.Editor__Toc.Length == toc.Count)
        {
            CustomDebug.LogError("tk2dSystem.UnmakeLoadableAsset - Unable to delete asset");
            return(false);
        }
        else
        {
            tk2dSystem.inst.Editor__Toc = toc.ToArray();
            EditorUtility.SetDirty(tk2dSystem.inst);
            AssetDatabase.SaveAssets();

            return(true);
        }
    }
    public static Dictionary <string, NestedPrefab> CollectGUIDMap(string filter, List <GameObject> duplicates = null)
    {
        Dictionary <string, NestedPrefab> map = new Dictionary <string, NestedPrefab>();
        List <NestedPrefab> prefabs           = AssetUtility.GetAssetsAtPath <NestedPrefab>(filter);

        foreach (NestedPrefab p in prefabs)
        {
            if (!p.IsNull())
            {
                if (!map.ContainsKey(p.prefabGuid))
                {
                    map.Add(p.prefabGuid, p);
                }
                else
                {
                    if (duplicates != null)
                    {
                        duplicates.Add(p.gameObject);
                    }

                    CustomDebug.LogError("NestedPrefab: Duplicate GUID pair :  " + p.name + "   +   " + map[p.prefabGuid].name);

                    p.GenerateNewGUID();
                    EditorUtility.SetDirty(p);
                    map.Add(p.prefabGuid, p);

                    CustomDebug.LogError("NestedPrefab: Rebuid GUID for " + p.name, p.gameObject);
                }
            }
        }

        return(map);
    }
示例#25
0
    public static void setSaveInt(SaveInt saveInt, int value)
    {
        CustomDebug.Log("[save]" + saveInt + " " + value);
        PlayerPrefs.SetInt(saveInt.ToString(), value);

        PlayerPrefs.Save();
    }
    private bool TryAddNewPair(PropertyWrapper wrapper, SerializedProperty newKey)
    {
        bool suchKeyExists = false;

        for (int i = 0; i < wrapper.Count; i++)
        {
            var curKey = wrapper.GetKeyAtIndex(i);
            if (Holder.KeysAreEqual(curKey, newKey))
            {
                suchKeyExists = true;
            }
        }

        if (!suchKeyExists)
        {
            int curSize = wrapper.Count;
            wrapper.InsertPairAtIndex(curSize);
            Holder.PutValue(wrapper.GetKeyAtIndex(curSize));
            wrapper.Apply();
            return(true);
        }
        else
        {
            CustomDebug.LogError("Key already exists " + newKey.ToString());
            return(false);
        }
    }
    public static void ValidateMesh(Mesh mesh)
    {
                #if UNITY_EDITOR
        if (mesh != null)
        {
            if (!mesh.isReadable)
            {
                string path = UnityEditor.AssetDatabase.GetAssetPath(mesh);
                UnityEditor.ModelImporter mImporter = UnityEditor.AssetImporter.GetAtPath(path) as UnityEditor.ModelImporter;
                mImporter.isReadable = true;
                UnityEditor.AssetDatabase.ImportAsset(path, UnityEditor.ImportAssetOptions.ForceUpdate);
            }

            bool      outOfRange = false;
            Vector2[] uv1        = mesh.uv;
            for (int i = uv1.Length - 1; i >= 0 && !outOfRange; i--)
            {
                Vector2 v = uv1[i];
                outOfRange = (v.x < 0) || (v.x > 1f) || (v.y < 0) || (v.y > 1f);
                if (outOfRange)
                {
                    CustomDebug.LogError("WRONG MESH UV : " + "(" + v.x + " : " + v.y + ")" + " : " + mesh.name);
                }
            }

            if (outOfRange)
            {
                CustomDebug.LogError("WRONG MESH UV : " + UnityEditor.AssetDatabase.GetAssetPath(mesh) + "/" + mesh.name);
            }
        }
                #endif
    }
    void Awake()
    {
        if (instance == null)
        {
            instance = this;

            if (Application.isPlaying)
            {
                DontDestroyOnLoad(gameObject);
            }
        }
        else
        {
            //can only be one tk2dUIManager at one-time, if another one is found Destroy it
            if (instance != this)
            {
                CustomDebug.Log("Discarding unnecessary tk2dUIManager instance.");

                if (uiCamera != null)
                {
                    HookUpLegacyCamera(uiCamera);
                    uiCamera = null;
                }

                Destroy(this);

                return;
            }
        }

        tk2dUITime.Init();
        Setup();
    }
示例#29
0
        public static void Save()
        {
            CustomDebug.Log("[ScoreStatics] Saved ScoreInfo", CustomDebug.Users.System, CustomDebug.Level.Info);
            PlayerPrefs.SetInt("HighScore", HighScore);

            PlayerPrefs.Save();
        }
示例#30
0
    static Texture2D LoadTextureEditor(string imagePath, bool doMipMaps)
    {
        Texture2D resultTexture = new Texture2D(4, 4, TextureFormat.RGBA32, doMipMaps);

        byte[] curImageBytes = null;
        if (File.Exists(imagePath))
        {
            curImageBytes = File.ReadAllBytes(imagePath);
        }
        else
        {
            resultTexture = null;
            CustomDebug.LogError("File <" + imagePath + "> does not exist");
        }

        if (curImageBytes == null || !resultTexture.LoadImage(curImageBytes))
        {
            if (curImageBytes == null)
            {
                CustomDebug.LogError("Image bytes is null");
            }
            else
            {
                CustomDebug.Log("Can't load image");
            }
            resultTexture = null;
        }

        return(resultTexture);
    }