Advertisement
ElectricJesus

AssetParameters

Aug 13th, 2016
225
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.48 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections.Generic;
  3. using AC;
  4.  
  5. [RequireComponent(typeof(ActionList))]
  6. public class AssetParameters : MonoBehaviour {
  7.    
  8.     public List<ActionParameter> parameters = new List<ActionParameter>();
  9.  
  10.     public void Start()
  11.     {
  12.         ApplyValues();
  13.     }
  14.    
  15.     public void ApplyValues()
  16.     {
  17.         var actionList = this.GetComponent<ActionList>();
  18.  
  19.         if (actionList.parameters.Count != this.parameters.Count)
  20.             throw new System.Exception("Number of parameters does not match ActionList.");
  21.  
  22.         for (int i = 0; i < actionList.parameters.Count && i < this.parameters.Count; i++)
  23.             actionList.parameters[i].CopyValues(this.parameters[i]);
  24.     }
  25.    
  26.     [ExecuteInEditMode]
  27.     public void SetParametersNumber(int num)
  28.     {
  29.         if (num < 0)
  30.             throw new System.Exception("Parameters number can't be less than zero.");
  31.  
  32.         if (this.parameters == null)
  33.             this.parameters = new List<ActionParameter>();
  34.         while (this.parameters.Count < num)
  35.             this.parameters.Add(new ActionParameter(-1));
  36.         while (this.parameters.Count > num)
  37.             this.parameters.RemoveAt(this.parameters.Count - 1);
  38.     }
  39. }
  40.  
  41. public static class Utils {
  42.     public static GameObject GetObjectByID (ConstantID id)
  43.     {
  44.         if (id == null)
  45.             return null;
  46.  
  47.         var res = Serializer.returnComponent<Transform>(id.constantID).gameObject;
  48.         return res;
  49.     }
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement