Ejemplo n.º 1
0
    void    OnEnable()
    {
        if (DSUI == null)
        {
            DSUI = DSM.UserIntent;
        }

        inputField = GetComponent <InputField> ();

        // to connect data flows from InputField to Datasack(s):
        inputField.onValueChanged.AddListener(OnValueChanged);
        inputField.onEndEdit.AddListener(OnEndEdit);

        // to connect data flows from Datasack to InputField:
        dataSackPayload.OnChanged += OnDatasackChanged;
        inputField.text            = dataSackPayload.Value;
    }
    void    OnChanged(Datasack ds)
    {
        int i = index;

        if (indexDatasack)
        {
            i = indexDatasack.iValue;
        }

        string display = ds.GetArrayValue(i);

        if (!System.String.IsNullOrEmpty(FormatString))
        {
            textAbstraction.SetText(System.String.Format(FormatString, display));
            return;
        }
        textAbstraction.SetText(display);
    }
Ejemplo n.º 3
0
    void    OnChanged(Datasack ds)
    {
        int n = ds.iValue;

        string text = "";

        if (n >= 0 && n < TextTable.Length)
        {
            text = TextTable[n];
        }

        if (!System.String.IsNullOrEmpty(FormatString))
        {
            textAbstraction.SetText(System.String.Format(FormatString, text));
            return;
        }
        textAbstraction.SetText(text);
    }
Ejemplo n.º 4
0
    void    OnChanged(Datasack ds)
    {
        var value = ds.fValue;

        if (Full > 0)
        {
            value /= Full;
        }
        if (dataSackFull)
        {
            var x = dataSackFull.fValue;
            if (x > 0)
            {
                value /= x;
            }
        }
        image.fillAmount = value;
    }
Ejemplo n.º 5
0
    void    OnUserIntent(Datasack ds)
    {
        Debug.Log(GetType() + ".OnUIIntent(): intent: " + ds.Value);

        DSM.AudioSourceClick.Poke();

        switch (ds.Value)
        {
        case "ButtonNewgame":
            NewGame();
            break;

        case "ButtonAddpoints":
            AddPoints();
            break;

        case "ButtonGameover":
            GameOver();
            break;

        case "InputField":
            DSM.AudioSourceEnter.Poke();
            Debug.Log("Entered:" + DSM.InputtedData.Value);
            break;

        case "ButtonPopup1":
            DSM.Popup1.Header.Value      = "Answer Me!";
            DSM.Popup1.Message.Value     = "WHAT is the airspeed velocity of an unladen swallow?";
            DSM.Popup1.Button1Text.Value = "African";
            DSM.Popup1.Button2Text.Value = "European";
            DSM.Popup1.Result.Clear();
            DSM.Popup1.Result.OnChangedOnceOnly += (xxx) => {
                Debug.Log("Result was " + xxx.Value);
            };
            popup1.Activate();
            break;

        default:
            Debug.LogWarning(GetType() + ".OnUIIntent(): unknown intent: " + ds.Value);
            break;
        }
    }
Ejemplo n.º 6
0
    void OnChanged(Datasack ds)
    {
        bool pokedTrue = ds.bValue;

        // boolean handling:
        foreach (var mb in ToEnable)
        {
            if (mb)
            {
                mb.enabled = pokedTrue;
            }
        }
        foreach (var mb in ToDisable)
        {
            if (mb)
            {
                mb.enabled = !pokedTrue;
            }
        }
    }
Ejemplo n.º 7
0
    void    OnChanged(Datasack ds)
    {
        Renderer[] rndrrs = null;

        if (AllChildRenderers)
        {
            rndrrs = GetComponentsInChildren <Renderer>();
        }
        else
        {
            rndrrs = new Renderer[] { GetComponent <Renderer>() };
        }

        int index = ds.iValue;

        foreach (var rndrr in rndrrs)
        {
            rndrr.material = MaterialTable[index];
        }
    }
Ejemplo n.º 8
0
    void    OnChanged(Datasack ds)
    {
        if (colorable)
        {
            int index = ds.iValue;

            if (MatchIndexValue)
            {
                int ActualIndexToCompare = IndexValueToMatch;
                if (UseSiblingIndex)
                {
                    ActualIndexToCompare = transform.GetSiblingIndex();
                }

                bool matching = (index == ActualIndexToCompare);
                index = matching ? 1 : 0;
            }

            colorable.SetColor(ColorTable[index]);
        }
    }
Ejemplo n.º 9
0
 public Datasack        Get(string sackname, bool Add = false)
 {
     if (!AllSacks.ContainsKey(sackname))
     {
         Datasack ds = null;
         if (Add)
         {
             ds          = ScriptableObject.CreateInstance <Datasack> ();
             ds.FullName = sackname;
         }
         if (ds)
         {
             ds.FullName = sackname;
             ds.LoadPersistent();
             AllSacks [sackname] = ds;
         }
         else
         {
             UnityEngine.Debug.LogError(GetType() + ".Get(): Datasack '" + sackname + "' does not exist. Set Add = true to add at runtime.");
             UnityEngine.Debug.LogWarning(s_ReminderToCodegen);
         }
     }
     return(AllSacks [sackname]);
 }
Ejemplo n.º 10
0
        void CreateStaticGetterExpression(ref string s, string indentation, Datasack ds, string variableName)
        {
            bool InsertExtraLineAfterwards = false;

            if (!string.IsNullOrEmpty(ds.Comments))
            {
                InsertExtraLineAfterwards = true;

                s += "\n";
                s += indentation + "\t// .Comments field from Datasack:\n";

                foreach (var comment in ds.Comments.Split(
                             new string[] { System.Environment.NewLine },
                             StringSplitOptions.RemoveEmptyEntries))
                {
                    s += indentation + "\t//\t" + comment + "\n";
                }
            }

            if (ds.Save)
            {
                InsertExtraLineAfterwards = true;

                s += "\n";
                s += indentation + "\t// Persistent (has .Save field checked in Datasack):\n";
            }

            s += indentation + "\tpublic static Datasack " + IdentifierSafeString(ds.name) +
                 " { get { return DSM.I.Get( \"" +
                 variableName + "\"); } }\n";

            if (InsertExtraLineAfterwards)
            {
                s += "\n";
            }
        }
Ejemplo n.º 11
0
    void OnUserIntent(Datasack ds)
    {
        switch (ds.Value)
        {
        case "PopupButton1":
        case "PopupButton2":
            DSM.Popup1.AudioButtonPress.Poke();

            chosenResult = ds.Value;                            // store for when animation is done

            StartDismiss();
            break;

        case "popup1_done":
            Debug.Log(GetType() + ": Popup1 dismissed with result '" + ds.Value + "'");

            Dismiss();

            DSM.Popup1.Result.Value = chosenResult;

            Destroy(this);
            break;
        }
    }
Ejemplo n.º 12
0
 void    OnChanged(Datasack ds)
 {
     image.color = ColorTable[ds.iValue];
 }
Ejemplo n.º 13
0
 void    OnChanged(Datasack ds)
 {
     image.fillAmount = ds.fValue;
 }
Ejemplo n.º 14
0
 void    OnChanged(Datasack ds)
 {
     em.rateOverTime = ds.fValue * BaseEmitOverTimeRate;
 }
Ejemplo n.º 15
0
    void OnChanged(Datasack ds)
    {
        bool pokedTrue = ds.bValue;

        // boolean handling:
        foreach (var go in ToEnable)
        {
            if (go)
            {
                go.SetActive(pokedTrue);
            }
        }
        foreach (var go in ToDisable)
        {
            if (go)
            {
                go.SetActive(!pokedTrue);
            }
        }

        if (OperateOnChildren)
        {
            if (transform.childCount != IndexArray.Length)
            {
                IndexArray = new GameObject[transform.childCount];
            }
            for (int i = 0; i < transform.childCount; i++)
            {
                IndexArray[i] = transform.GetChild(i).gameObject;
            }
        }

        // iValue integer list selections
        for (int i = 0; i < IndexArray.Length; i++)
        {
            var currentGameObject = IndexArray[i];
            if (currentGameObject)
            {
                // presume selection SelectionStrategy.SELECT_EXACTLY_ONE:
                bool onoff = i == ds.iValue;

                switch (selectionStrategy)
                {
                case SelectionStrategy.SELECT_LESS_THAN:
                    onoff = i < ds.iValue;
                    break;

                case SelectionStrategy.SELECT_LESS_THAN_OR_EQUAL:
                    onoff = i <= ds.iValue;
                    break;

                case SelectionStrategy.SELECT_BY_GAMEOBJECT_NAME:
                    onoff = (ds.Value == currentGameObject.name);
                    break;
                }

                if (InvertSelectionStrategy)
                {
                    onoff = !onoff;
                }

                currentGameObject.SetActive(onoff);
            }
        }
    }
Ejemplo n.º 16
0
        public override void OnInspectorGUI()
        {
            Datasack ds = (Datasack)target;

            DrawDefaultInspector();

            EditorGUILayout.BeginVertical();

            if (GUILayout.Button("CODEGEN"))
            {
                GenerateCode();
            }

            GUILayout.Space(20);

            if (GUILayout.Button("RUNTIME POKE"))
            {
                ds.Poke();
            }

            GUILayout.Space(20);

            if (GUILayout.Button("RUNTIME TOGGLE"))
            {
                ds.bValue = !ds.bValue;
            }

            GUILayout.Space(20);

            GUI.color = Color.green;
            if (GUILayout.Button("RESET TO INITIAL VALUE"))
            {
                ds.Value = ds.InitialValue;
            }

            GUILayout.Space(20);

            GUI.color = Color.cyan;
            if (GUILayout.Button("OUTPUT CURRENT VALUE"))
            {
                string part1 = "Datasack " + ds.FullName + " is currently: '" + ds.Value + "'";
                string part2 = " <not parseable as float>";
                try
                {
                    part2 = "--> as float value = " + ds.fValue;
                }
                catch { }                               // gotta catch 'em all: fairly harmless in a small context
                Debug.Log(part1 + part2);
            }

            GUILayout.Space(20);

            GUI.color = Color.yellow;
            if (GUILayout.Button("DELETE SAVED VALUE"))
            {
                if (PlayerPrefs.HasKey(PlayerPrefsKey()))
                {
                    PlayerPrefs.DeleteKey(PlayerPrefsKey());
                    PlayerPrefs.Save();
                }
            }

            GUILayout.Space(20);

            GUI.color = Color.red;
            if (GUILayout.Button("DELETE ALL PLAYER PREFS"))
            {
                if (EditorUtility.DisplayDialog("CONFIRM!",
                                                "Confirm DELETE all PlayerPrefs stored settings?\n\n" +
                                                "(THIS ACTION CANNOT BE UNDONE!)", "DELETE ALL PREFS", "Cancel"))
                {
                    DSM.ResetDictionaryIfRunning();
                    PlayerPrefs.DeleteAll();
                    PlayerPrefs.Save();
                }
            }

            GUILayout.Space(20);

            GUI.color = ds.DebugBreak ? Color.white : Color.gray;

            GUILayout.BeginHorizontal();
            GUILayout.Label("Debug Break", GUILayout.Width(160));
            ds.DebugBreak = GUILayout.Toggle(ds.DebugBreak, "BREAK");
            GUILayout.EndHorizontal();

            GUI.color = ds.DebugLogging ? Color.white : Color.gray;

            GUILayout.BeginHorizontal();
            GUILayout.Label("Debug Logging", GUILayout.Width(160));
            ds.DebugLogging = GUILayout.Toggle(ds.DebugLogging, "LOG");
            GUILayout.EndHorizontal();

            EditorGUILayout.EndVertical();
        }
Ejemplo n.º 17
0
 void    OnChanged(Datasack ds)
 {
     colorable.SetColor(ds.colorValue);
 }
Ejemplo n.º 18
0
 void    OnChangedFOV(Datasack ds)
 {
     cam.fieldOfView = ds.fValue;
 }
Ejemplo n.º 19
0
 void    OnChangedOrthoSize(Datasack ds)
 {
     cam.orthographicSize = ds.fValue;
 }
Ejemplo n.º 20
0
 void    OnChangedRect(Datasack ds)
 {
     cam.rect = ds.rValue;
 }
Ejemplo n.º 21
0
 void CreateStaticGetterExpression(ref string s, Datasack ds, string variableName)
 {
     s += "\tpublic static Datasack " + IdentifierSafeString(ds.name) +
          " { get { return DSM.I.Get( \"" +
          variableName + "\"); } }\n";
 }
Ejemplo n.º 22
0
 void    OnDatasackChanged(Datasack ds)
 {
     slider.value = ds.fValue;
 }
Ejemplo n.º 23
0
        void GenerateCode()
        {
            Debug.Log("CODEGEN!");

            string s = "//\n//\n//\n" +
                       "// MACHINE-GENERATED CODE - DO NOT MODIFY BY HAND!\n" +
                       "//\n" +
                       "// NOTE: You definitely SHOULD commit this file to source control!!!\n" +
                       "//\n//\n" +
                       "// To regenerate this file, select any Datasack object, look\n" +
                       "// in the custom Inspector window and press the CODEGEN button.\n" +
                       "//\n//\n//\n";

            s += "public partial class DSM\n{\n";

            // This now scans the entire project for Datasacks,
            // not just underneath the Resources directories.

            string[] datasackGUIDs = AssetDatabase.FindAssets("t:Datasack");
            int      numDatasacks  = datasackGUIDs.Length;

            Dictionary <string, List <Datasack> > SplitByDirectory = new Dictionary <string, List <Datasack> >();

            string[] datasackPaths = new string[numDatasacks];
            for (int i = 0; i < numDatasacks; i++)
            {
                datasackPaths[i] = AssetDatabase.GUIDToAssetPath(datasackGUIDs[i]);
            }

            System.Array.Sort(datasackPaths);

            Datasack[] sacks = new Datasack[numDatasacks];

            for (int i = 0; i < datasackGUIDs.Length; i++)
            {
                string assetPath = datasackPaths[i];

                sacks[i] = AssetDatabase.LoadAssetAtPath <Datasack>(assetPath);

                var ds = sacks[i];

                string dirName = System.IO.Path.GetDirectoryName(assetPath);
                if (!SplitByDirectory.ContainsKey(dirName))
                {
                    SplitByDirectory[dirName] = new List <Datasack>();
                }
                SplitByDirectory[dirName].Add(ds);
            }

            // When producing the nested class name that will represent each subfolder,
            // we search upwards and stop when we hit a folder named any of these values.
            //
            // This means datasacks at any of these folders will be presented as
            // "flat namespace," i.e., just DSM.MyName rather than DSM.Folder.MyName.
            List <string> SpecialDirectoriesThatBeginDatasackNamespacing = new List <string>
            {
                "Resources",
                "Datasacks",
                "Datasack",
                "Assets",
            };

            foreach (var dirName in SplitByDirectory.Keys)
            {
                string pathPrefix  = "";
                string indentation = "";

                string[] directoryParts = dirName.Split(
                    new char[] {
                    System.IO.Path.DirectorySeparatorChar,
                    System.IO.Path.AltDirectorySeparatorChar,
                },
                    StringSplitOptions.RemoveEmptyEntries);

                string classDefinitionOpen  = "";
                string classDefinitionClose = "";

                int partsToInclude = 0;
                for (int i = directoryParts.Length - 1; i >= 0; i--)
                {
                    if (SpecialDirectoriesThatBeginDatasackNamespacing.Contains(directoryParts[i]))
                    {
                        break;
                    }
                    partsToInclude++;
                }

                for (int i = 0; i < partsToInclude; i++)
                {
                    int    partNumber = (directoryParts.Length - partsToInclude) + i;
                    string part       = directoryParts[partNumber];

                    pathPrefix += part + "/";

                    indentation = indentation + "\t";

                    // append
                    classDefinitionOpen += indentation + "public static partial class " + IdentifierSafeString(part) + "\n";
                    classDefinitionOpen += indentation + "{\n";

                    // prepend!!
                    classDefinitionClose = indentation + "}\n" + classDefinitionClose;
                }

                s += "\n";
                s += "// Datasacks from directory '" + dirName + "'\n";

                s += classDefinitionOpen;

                foreach (var ds in SplitByDirectory[dirName])
                {
                    string variableName = pathPrefix + ds.name;
                    CreateStaticGetterExpression(ref s, indentation, ds, variableName);
                    ds.FullName = variableName;
                }

                s += classDefinitionClose;
            }

            s += "}\n";

            s += "\n// Total of " + numDatasacks + " datasacks found and processed.\n";

            Debug.Log(s);

            {
                System.IO.Directory.CreateDirectory(DSM.s_AllDatasacksDirectory);

                string outfile = DSM.s_AllDatasacksDirectory + "DSMCodegen.cs";
                using (System.IO.StreamWriter sw =
                           new System.IO.StreamWriter(outfile, false))
                {
                    sw.Write(s);
                }
            }

            {
                bool create = false;

                string assetPath = DSM.s_AllDatasacksResources;

                System.IO.Directory.CreateDirectory(assetPath);

                assetPath = assetPath + DSM.s_AllDatasacksAsset + ".asset";

                var dsc = AssetDatabase.LoadAssetAtPath <DatasackCollection>(assetPath);
                if (!dsc)
                {
                    create = true;
                    dsc    = ScriptableObject.CreateInstance <DatasackCollection>();
                }

                dsc.Mappings = new DatasackCollection.DatasackMapping[sacks.Length];

                for (int i = 0; i < sacks.Length; i++)
                {
                    dsc.Mappings[i]          = new DatasackCollection.DatasackMapping();
                    dsc.Mappings[i].Fullname = sacks[i].FullName;
                    dsc.Mappings[i].Datasack = sacks[i];
                }

                if (create)
                {
                    AssetDatabase.CreateAsset(dsc, assetPath);
                }

                EditorUtility.SetDirty(dsc);

                AssetDatabase.SaveAssets();
            }

            AssetDatabase.Refresh();
        }
 void OnChangedFormatting(Datasack fmt)
 {
     OnChangedData(dataSack);
 }
Ejemplo n.º 25
0
 void OnChanged(Datasack ds)
 {
     desiredVolume = ds.fValue;
 }
Ejemplo n.º 26
0
 void    OnDatasackChanged(Datasack ds)
 {
     toggle.isOn = ds.bValue;
 }
Ejemplo n.º 27
0
 // Data flowing from Datasack to InputField
 void    OnDatasackChanged(Datasack ds)
 {
     inputField.text = ds.Value;
 }
Ejemplo n.º 28
0
        public override void OnInspectorGUI()
        {
            Datasack ds = (Datasack)target;

            DrawDefaultInspector();

            EditorGUILayout.BeginVertical();

            if (GUILayout.Button("CODEGEN"))
            {
                GenerateCode();
            }

            GUILayout.Space(20);

            if (GUILayout.Button("RUNTIME POKE"))
            {
                ds.Poke();
            }

            GUILayout.Space(20);

            if (GUILayout.Button("RUNTIME TOGGLE"))
            {
                ds.bValue = !ds.bValue;
            }

            GUILayout.Space(20);

            GUI.color = Color.green;
            if (GUILayout.Button("RESET TO INITIAL VALUE"))
            {
                ds.Value = ds.InitialValue;
            }

            GUILayout.Space(20);

            GUI.color = Color.cyan;
            if (GUILayout.Button("OUTPUT CURRENT VALUE"))
            {
                Debug.Log(ds.DisplayDebugOutput());
            }

            GUILayout.Space(20);

            GUI.color = Color.yellow;
            if (GUILayout.Button("DELETE SAVED VALUE"))
            {
                if (PlayerPrefs.HasKey(PlayerPrefsKey()))
                {
                    PlayerPrefs.DeleteKey(PlayerPrefsKey());
                    PlayerPrefs.Save();
                }
            }

            GUILayout.Space(20);

            GUI.color = Color.red;
            if (GUILayout.Button("DELETE ALL PLAYER PREFS"))
            {
                if (EditorUtility.DisplayDialog("CONFIRM!",
                                                "Confirm DELETE all PlayerPrefs stored settings?\n\n" +
                                                "(THIS ACTION CANNOT BE UNDONE!)", "DELETE ALL PREFS", "Cancel"))
                {
                    DSM.ResetDictionaryIfRunning();
                    PlayerPrefs.DeleteAll();
                    PlayerPrefs.Save();
                }
            }

            GUILayout.Space(20);

            GUI.color = ds.DebugBreak ? Color.white : Color.gray;

            GUILayout.BeginHorizontal();
            GUILayout.Label("Debug Break", GUILayout.Width(160));
            ds.DebugBreak = GUILayout.Toggle(ds.DebugBreak, "BREAK");
            GUILayout.EndHorizontal();

            GUI.color = ds.DebugLogging ? Color.white : Color.gray;

            GUILayout.BeginHorizontal();
            GUILayout.Label("Debug Logging", GUILayout.Width(160));
            ds.DebugLogging = GUILayout.Toggle(ds.DebugLogging, "LOG");
            GUILayout.EndHorizontal();

            EditorGUILayout.EndVertical();
        }
Ejemplo n.º 29
0
        string PlayerPrefsKey()
        {
            Datasack ds = (Datasack)target;

            return(DSM.s_PlayerPrefsPrefix + ds.FullName);
        }