private GameObject CreateCopyFromMeshObj(string copyFromName, string objPath, float opacity)
        {
            // Find a matching game object within the mesh object and "copy" it
            // (In Unity terms, the Instantiated object is a copy)
            UnityEngine.Object[] objects = AssetDatabase.LoadAllAssetsAtPath(objPath);
            foreach (var obj in objects)
            {
                if (obj.name != copyFromName)
                {
                    continue;
                }

                // We have a match but is it a game object?
                GameObject gameObj = GameObject.Instantiate(obj) as GameObject;
                if (gameObj == null)
                {
                    continue;
                }

                // Add a component that will control our initial shader properties
                TiledInitialShaderProperties shaderProps = gameObj.AddComponent <TiledInitialShaderProperties>();
                shaderProps.InitialOpacity = opacity;

                // Reset the name so it is not decorated by the Instantiate call
                gameObj.name = obj.name;
                return(gameObj);
            }

            // If we're here then there's an error with the mesh name
            Debug.LogError(String.Format("No mesh named '{0}' to copy from.", copyFromName));
            return(null);
        }
Пример #2
0
 public void HandleCustomProperties(UnityEngine.GameObject gameObject,
                                    IDictionary <string, string> props)
 {
     // Simply add a component to our GameObject
     if (props.ContainsKey("opacity"))
     {
         try
         {
             string prop    = props["opacity"];
             float  opacity = float.Parse(prop);
             Tiled2Unity.TiledInitialShaderProperties properties = gameObject.GetComponentInChildren <Tiled2Unity.TiledInitialShaderProperties>();
             properties.InitialOpacity = opacity;
         }
         catch (Exception e)
         {
             Debug.LogError(e.Message);
         }
     }
 }